当特定类型的用户登录时,我试图让我的 Yii 应用程序在设定的秒数后自动注销。
我对我的 protected/components/WebUser.php 文件进行了以下修改:
public function init() {
parent::init();
if (($user = $this->getState('userModel')) !== null) {
$this->setUserData(unserialize($user));
if ($this->isNonAdminUser()) {
$this->authTimeout = 3600; // 1 hour timeout
}
}
$this->updateAuthStatus();
}
// function automatically directly after $this->logout()
protected function afterLogout() {
Yii::app()->request->redirect(('site/front/login'));
//Yii::app()->request->redirect((Yii::app()->user->returnUrl));
}
这基本上会在 1 小时无活动后将“非管理员用户”从会话中注销 - 这很有效,但是我也希望能够“强制”他们回到主页。我尝试在 afterLogout() 中使用重定向功能,但由于某种原因它似乎没有进行重定向?
有什么想法为什么不呢?
注意 - 我使用的是 Yii 1.x