我的登录方法:
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
, 但不适用于random
or category
...
知道为什么吗?