tags:

views:

658

answers:

3

I created module for admin specific operations. I don't want to write the same access rules for every controller, it's not pretty coding style.

+1  A: 

One solution would be extend a common BaseClass Controller for every class authenticated.

This way you can write once.

Ismael
Yes, I can, but I think module can contain logic for managing its controllers, otherwise I don't know the sense of module.
YS-PRO
+1  A: 

Module is like a sub-application with separated directory structure. It is not responsible for filtering or checking for permission.

The only vital solution is to define a new abstraction as Ismael proposed.

class ExtendedController
{
    public function rules()
    {
        return array_merge(parent::rules(), array(
           // your rules
        ));
    }
}
pestaa
A: 

Ismael and pestaa choices are very good even fast to implement, nevertheless I always recommend more powerful alternatives like RBAC model. You can find a very good GUI for Yii RBAC in http://code.google.com/p/srbac/

robregonm