Access Rules Expressions Parameters


I want to create an access rule exprenession, using a “Rules” model that I’ve written.

Now, I have a table - Articles. In that rule I want to check if the authenticated user is the owner

of this article. if he is, or if the authenticated user access is 5, the method will return true, and else it returns false.

the method:

public function UpdateArticle($model)


		if( Yii::app()->user->isGuest )

			return false;

		if( Yii::app()->user->id === $model->author_id)

			return true;

		if( Yii::app()->user->auth === 5 )

			return true;



		return false;


Now, how can I pass the $model to this method using controller acess rules?



		'expression'=>array('Rules', 'UpdateArticle'),



If you look at the CAccessRule.expression docu you see that your function signature is wrong (no $user and $rule parameter). In comment 1976 you see an example.

In your custom rule validation method you have access to e.g. AR methods like

$model= YourModel::model()->findByPk(...); // or whatever

$authorId = $model->author_id;

Thanks :)