CakePHP会话过期重定向到/ users / login

时间:2014-01-03 07:36:43

标签: session cakephp redirect

因为我将重定向设置为/ admins / login而导致这些重定向出现问题,这是我在CakePHP上的AppContoller

class AppController extends Controller {
public $components = array(
    'Acl',
    'Auth' => array(
        'authenticate' => array(
             'Form' => array(
                'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
                ),
                "userModel" => "Admin",
             )
        )
    ),
    'Session',
);

public $helpers = array(
    'Html', 
    'Form', 
    'Session'
);

public function beforeFilter() {

    $this->Auth->loginAction = array('controller' => 'admins', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'admins', 'action' => 'login');
    $this->Auth->loginRedirect = "events/admin_index";
    //$this->Auth->loginRedirect = array('controller' => 'events', 'action' => 'admin_index'); ibutang pa ni nako nga code
}

public function beforeRender() {

    $this->set("sessions", $this->Auth->user());
    $this->set("params", $this->params);

}

}

重定向到/ users / login很少见,但仍想知道它为什么会转到该链接。如果有人能向我解释,我会很高兴。

PS:我的项目不是我的,它是由我处理的。

2 个答案:

答案 0 :(得分:0)

您是否在Config / core.php中检查了会话的持续时间?如果它被设置为'php'(默认值),也许你的php.ini是关于会话持续时间的简短。因此,您可以重定向到/ users / login,因为在您尝试访问受限管理员视图时会话已过期,因此Auth会要求您再次登录。

您可以使用CakePHP session handler选择会话保持活动的方式和时长。

答案 1 :(得分:0)

您可以像这样设置loginRedirect和logoutRedirect。

public $components = array(
    'Session',
    'Auth' => array(
        'loginRedirect' => array(
            'controller' => 'users',
            'action' => 'index'
        ),
        'logoutRedirect' => array(
            'controller' => 'users',
            'action' => 'login'
        )
    )
);
相关问题