tags:

views:

224

answers:

1

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',
));
}
A: 

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}",
));
}


mmattax