如何在yii框架控制器中传递参数来访问规则表达式

liy*_*ysd 4 php yii

将参数传递给accessRules exressions下面的代码不起作用因为$ owner_id没有在评估表达式的类中定义.任何想法如何解决它?

public function accessRules(){
$owner_id = $this->loadModel()->owner_id;
return array(
...
        array('allow', 
                'actions'=>array('update'),
                'expression'=>'$user->id==$owner_id',
));
}
Run Code Online (Sandbox Code Playgroud)

mma*_*tax 7

很难说出你要做什么或问题是什么,但在构建数组时我会使用"{}"和双引号而不是单引号,以便正确解释变量:


public function accessRules(){
$owner_id = $this->loadModel()->owner_id;
return array(
...
        array('allow', 
                'actions'=>array('update'),
                'expression'=>"{$user->id}=={$owner_id}",
));
}