Yii 1.1: How to create Module based Login

7 followers

Lets say we have 3 modules (customer, user, admin) in an application and we need, separate logins for each module.

We can achieve this by adding a prefix to the name of session variable for each module.

Lets take 'admin' module:

Inside your admin/AdminModule.php file, add the following lines to the 'init' function

Yii::app()->user->setStateKeyPrefix('_admin');

OR

Yii::app()->setComponents(array(
            'errorHandler' => array(
                'errorAction' => 'admin/default/error',
            ),
            'user' => array(
                'class' => 'CWebUser',
                'stateKeyPrefix' => '_admin',
                'loginUrl' => Yii::app()->createUrl($this->getId() . '/default/login'),
            ),
        ));

Total 1 comment

#16256 report it
trond at 2014/02/03 05:16pm
Clever

Almost too simple...

Leave a comment

Please to leave your comment.

Write new article