0

我的登录方法:

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash('Please enter a valid username or password', 'errors/flash_error');
        }
    }
}

由于某种原因,它不会总是在它重定向到的页面上显示会话信息。我有一个名为的页面/random被路由到:

Router::connect('/random', array('controller' => 'submissions', 'action' => 'random'));

当我去时/random,它不会显示这个:

<?= $this->Session->read('Auth.User.username'); ?>

但如果我去任何其他页面,它会..

在我的 SubmissionsController.php 中beforeFilter()

public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->loginRedirect = array(
        'controller' => 'users',
        'action' => 'login');
    $this->Auth->allow(
            'popular',
            'newest',
            'random',
            'view',
            'category',
    );
    $this->Auth->flash['element'] = 'errors/flash_error';
    $this->Auth->authError = 'Please login or sign up to submit a link.';
}

适用于popular, newest, view, 但不适用于randomor category...

知道为什么吗?

4

1 回答 1

0

原来我flush()在我的 default.ctp 中使用。这导致了奇怪的会话问题。对于遇到类似问题的任何人,我建议不要使用它。

于 2012-08-29T18:13:44.027 回答