大家好,我已经看过很多Yii 2 RBAC教程,但我真的不太欣赏如何实现规则.在Yii 2指南中,他们介绍了如何制定规则,但实际上并不是如何在控制器的行为或其他地方实现规则.关于这个问题我真的需要一些启示.
我现在拥有的是一个文件上传系统,我有两个角色,即admin和encoder.基本上,admin角色可以完成所有操作,而编码器角色只能创建,查看拥有,更新拥有和删除拥有.我已经创建了一个名为encodedBy的规则.
这是我在EncoderRule中的代码
namespace app\rbac; use yii\rbac\Rule;
/** * Checks if encoded_by matches user passed via params */ class EncoderRule extends Rule {
public $name = 'encodedBy';
/**
* @param string|integer $user the user ID.
* @param Item $item the role or permission that this rule is associated with
* @param array $params parameters passed to ManagerInterface::checkAccess().
* @return boolean a value indicating whether the rule permits the role or permission it is associated with.
*/
public …Run Code Online (Sandbox Code Playgroud) 以下是我视图中的ajax脚本.
$js = <<< JS
$('.list-link').click(function(){
$.ajax({
url: '?r=public/getlist¶m1=01¶m2=02¶m3=03',
dataType: "json",
success: function(data) {
$(".well").html(data.id);
}
})
});
JS;
$this->registerJs($js);
Run Code Online (Sandbox Code Playgroud)
现在我的问题是如何将param1,param2和param3的值设置为动态,就像我要从php变量传递params1到3.