Module accessControl

How to protect a whole module with accessRules?

e.g. only admin has access

I think a checkAccess in the module class’ beforeControllerAction would do it.

can you provide some code?

Something like this:




class MyAdminModule extends CWebModule

{

	public function beforeControllerAction($controller, $action)

	{

		return Yii::app()->user->checkAccess('admin') && parent::beforeControllerAction($controller, $action);

	}

}



it doesnt work for me, so i tried a new Controller




class AdminController extends CController

{

    public function filters()

    {

        return array(

            'accessControl',

        );

    }


    public function accessRules()

    {

        return array(


            array(

                'deny',

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

            ),


            array(

                'allow',

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

            )

            

        );

    }

}


class DefaultController extends AdminController

{

    public function actionIndex()

    {

        $this->render('index');

    }

}



This doesnt work either: ‘You are not authorized to perform this action.’

Why not?

First allow admin then deny the rest?

/Tommy

right, got it! thanks