【发布时间】:2015-12-26 11:55:40
【问题描述】:
我是 Yii 新手,不确定是否可以从 url 获取操作和控制器名称,例如:
/my_proj/backend/web/index.php?r=user%2Fcreate
我需要将它们放入控制器 (php) 或客户端 (jQuery)。
我需要它,因为点击按钮时:
<?= Html::button(Yii::t('app', Yii::t('app','Create')), ['value' => Url::to(['create']),'class' => 'btn btn-success modalButton', 'id' => 'create-user']) ?>
我想检查当前用户是否具有create 操作的权限。我在客户端需要这个,因为我在模式对话框中显示创建视图,如果用户没有权限,我不需要显示弹出窗口。
$(".modalButton").click(function(){
var permission = ?? //$(this)[0].id; //id works ok, but looking for another way
$.get('index.php?r=site/check-permission', {'permission': permission}, function(isAllowed){
if(isAllowed == 1)
{
$(".modal").modal("show")
.find(".modalContent")
.load($(".modalButton").attr('value'));
}
});
return false;
});
我尝试使用id 作为按钮,并在那里指定权限,但正在寻找另一种解决方案。
【问题讨论】:
标签: php jquery yii2 yii2-advanced-app