Hi

Hi,

I know there is a way in Yii to check an access rule, based on a custom rule etc.

i.e. Yii::app()->user->checkAccess("somecustomrule", array("id" => 1));

But is there just a way to check if the currently logged in user can access the controller and action based on the access rules table i.e.




array("allow",

				

	"controllers" => array("site"),

	"actions" => array("admin"),

	"users" => array("@"),

				

),

				

array("allow",

				

	"controllers" => array("site"),

	"actions" => array("help"),

	"users" => array("@"),

				

),



As you can see some of these do not have a custom rule. I need a way of saying is site/help accessible to currently logged in user?

In the site controller define this method:




    public function accessRules() {

        return array(

            array('allow',

                'actions'=>array('help'),

                'users'=>array('@'),

            ),

            array('deny',

                'users'=>array('*'),

            ),

        );

    }



That allows any logged in user to access the help page. The last entry enforces a "default deny" policy, that is anything that is not explicitly allowed is forbidden. You will probably need to add there other actions.

Hi JamesBarnsley.

Try isUserAllowed() method of CAccessRule class, see Class reference.