[英]cakePHP - redirect after login
首先要说我也检查了这个答案和这个其他答案,但似乎并不能解决问题。
预期结果:成功登录后,重定向到“ / admin / dashboard / index”
实际结果:成功登录后,应用程序将重定向到“ / users / login”。 登录正确,我可以在会话中看到它。 另外,在浏览器中手动导航到“ / admin / dashboard”时,它会重定向到“ / admin”,然后按照Config / routes.php中定义的规则进行无限重定向循环
这里相关代码:
在Config / core.php中
Configure::write( 'Routing.prefixes', array( 'admin' ) );
在Config / routes.php中
Router::connect( '/admin', array( 'controller' => 'dashboard', 'action' => 'index', 'admin' => true ) );
这是我在UsersController中的登录操作
if ( $this->request->is( 'post' ) ) {
if ( $this->Auth->login() ) {
$this->redirect( $this->Auth->redirectUrl() );
} else {
$this->BASession->err( __( 'Login error. Please check your data!' ) );
}
}
最后,这是我的Auth配置
$this->Auth->loginAction = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->logoutRedirect = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->loginRedirect = array( 'controller' => 'dashboard', 'action' => 'index', 'admin' => true );
$this->Auth->autoRedirect = true;
相关的说随着
$this->Auth->autoRedirect = false;
没有任何区别。
存在带有空“ admin_index”功能的DashboardController类,甚至是空白视图。
在登录功能中,调试“ $ this-> Auth-> redirectUrl()”显示为“ / admin”
PHP 5.4.10版-cakePHP 2.5.1版
我希望我提供了足够的信息,如果没有,请他们提供。
谢谢!
在AppController.php中编写以下代码
public function beforeFilter() {
$this->Auth->loginAction = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->logoutRedirect = array( 'controller' => 'users', 'action' => 'login', 'admin' => false );
$this->Auth->loginRedirect = array( 'controller' => 'dashboard', 'action' => 'index', 'admin' => true );
}
UsersController中的登录操作
if ( $this->request->is( 'post' ) ) {
if ( $this->Auth->login() ) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Your username or password was incorrect.'));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.