How to create Module based Login

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'),
            ),
        ));
1 0
7 followers
Viewed: 22 357 times
Version: 1.1
Category: How-tos
Written by: Ibrar Turi
Last updated by: CeBe
Created on: Jan 29, 2014
Last updated: 10 years ago
Update Article

Revisions

View all history

Related Articles