ow to pass arguments to accessRules experessions The code below doesn't work becouse $owner_id is not defined in class where expression is evaluated. Any ideas how to fix it?
public function accessRules(){
$owner_id = $this->loadModel()->owner_id;
return array(
...
array('allow',
'actions'=>array('update'),
'expression'=>'$user->id==$owner_id',
));
}
It's very hard to tell what you're trying to do or what the problem is, but I would use "{}" and double quotes rather than single quotes when building your array so that your variables are interpreted correctly:
public function accessRules(){
$owner_id = $this->loadModel()->owner_id;
return array(
...
array('allow',
'actions'=>array('update'),
'expression'=>"{$user->id}=={$owner_id}",
));
}
You can use
array('allow',
'actions'=>array('update'),
'users'=>array(Yii::app()->user->name),
'expression' => '(Yii::app()->user->id == ($_GET[\'id\']))',
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With