How to use Expression in default AccessControl to allow only the owner to do some action

Comparing #2 with #3

Revision #3 was created by whatif whatif on Jul 31, 2013, 3:06:37 AM.

You can use $this instead of "ExampleController" if the check method is in the same controller.

Content

[...]
In this ExampleController, it uses the default accessControl and accessRule.

In this default accessRule, add actions to allow ( 'view', 'update', 'delete' ) and expression for it ( array('ExampleController','allowOnlyOwner') ).

"ExampleController" is the class where the method 'allowOnlyOwner' is.
These can be any other class and method.
 You can use $this instead of "ExampleController" if 'allowOnlyOwner" is in the same controller as accessRules.

In function allowOnlyOwner, I assumed that the user class has 'isAdmin' property ( Yii::app()->user->isAdmin ). This can be any other condition if you can check if the user is 'admin'.

For example,
[...]