logoutRedirect()在cakePHP中不起作用

时间:2017-06-20 14:04:43

标签: cakephp-2.3

在我的app控制器中我定义为

class AppController extends Controller {

    public $components = array(
       // 'DebugKit.Toolbar',
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'admin_logins', 'action' => 'dashboard'),
            'logoutRedirect' => array('controller' => 'admin_logins', 'action' => 'index'),
            'authError' => 'You must be logged in to view this page.',
            'loginError' => 'Invalid Username or Password entered, please try again.',
            'authenticate' => array('Form' => array('fields' => array('username' => 'email', 'password' => 'password'))
            )

    ));
..........
?>

如果会话超时而不是重定向到admin_logins/index,它会重定向到users/login

我在app控制器的beforeFilter()内打印了logoutRedirect网址,如下所示

// only allow the login controllers only
    public function beforeFilter() {
        $this->Auth->authorize = 'Controller';
        $this->Auth->allow('index');
        pr($this->Auth->logoutRedirect); die;
}

打印如下

Array
(
    [controller] => admin_logins
    [action] => index
)

但它仍会重定向到users/login有人可以在这里建议吗?

1 个答案:

答案 0 :(得分:0)

我的错误。我错过了在loginAction中定义AppController。修改我的$components后,它工作正常。

public $components = array(
       // 'DebugKit.Toolbar',
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'admin_logins', 'action' => 'dashboard'),
            'loginAction'=>array('controller'=>'admin_logins', 'action'=>'index'),
            'logoutRedirect' => array('controller' => 'admin_logins', 'action' => 'index'),
            'authError' => 'You must be logged in to view this page.',
            'loginError' => 'Invalid Username or Password entered, please try again.',
            'authenticate' => array('Form' => array('fields' => array('username' => 'email', 'password' => 'password'))
            )

    ));