How to override Yii Login URL Modul for module?
here is the main configuration for base application:
return array(
.........
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl' => '/site/login',
),
..........
);
And then i have agent module, i want in this this module the login URL is different and login method is also different.
class AgentModule extends CWebModule {
public function init() {
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'agent.models.*',
'agent.components.*',
));
$this->defaultController = 'default';
$this->layoutPath = Yii::getPathOfAlias('agent.views.layout');
$this->components = array(
'user' => array(
'class' => 'AgentUserIdentity',
'loginUrl' => '/agent/default/login',
)
);
}
.......
But i don't know why this not work. Please help... (T.T)
Use this code
class AgentModule extends CWebModule {
public $assetsUrl;
public $defaultController = 'Login';
public function init() {
// this method is called when the module is being created
$this->setComponents(array(
'errorHandler' => array(
'errorAction' => 'admin/login/error'),
'user' => array(
'class' => 'CWebUser',
'loginUrl' => Yii::app()->createUrl('admin/login'),
)
)
);
Yii::app()->user->setStateKeyPrefix('_admin');
// import the module-level models and components
$this->setImport(array(
'admin.models.*',
'admin.components.*',
)
);
}
public function beforeControllerAction($controller, $action) {
if(parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller
//action is performed
$route = $controller->id . '/' . $action->id;
$publicPages = array(
'login/login',
'login/error',
);
if (Yii::app()->user->name !== 'admin' && !in_array($route,
$publicPages)) {
Yii::app()->getModule('admin')->user->loginRequired();
} else {
return true;
}
}
else
return false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With