【发布时间】:2026-01-31 11:35:02
【问题描述】:
我想让Auth 访问我的用户控制器的login()、logout() 和add() 操作,但我是否使用$this->Auth->allow('logout'); 并不重要,我会收到消息:@ 987654326@ login() 和 add() 工作正常。
这是我的 AppContoller.php:
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array(
'username' => 'email', 'password' => 'password')
)
),
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'landing')
), 'Session'
);
public function beforeFilter() {
$this->Auth->allow('add', 'login');
}
}
这是我的 UsersController.php 的相关部分:
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('logout');
}
public function logout() {
$this->set('title_for_layout', 'Logout');
$this->redirect($this->Auth->logout());
}
有人看到这里的问题吗?感谢您的帮助。
【问题讨论】:
-
快速浏览一下我可以看到一个小问题,在重定向之前设置标题是没有意义的,尽管它不应该成为您的问题的一个因素。您重定向到的页面是 Auth->allowed?
-
@Daniel,是的,正如您在 UserController.php 的 beforeFilter 函数中看到的那样,它是允许身份验证的。
-
抱歉,我的意思是 logoutRedirect 操作 - /pages/display/landing。
标签: php authentication cakephp-2.0 logout