Cakephp 登录时重定向
我希望用户在登录时被重定向到posts索引操作。但他们却被重定向到了posts的add操作。 下面是我的routes.phpCakephp 登录时重定向,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我希望用户在登录时被重定向到posts索引操作。但他们却被重定向到了posts的add操作。 下面是我的routes.php Router::connect('/', array('controller' => 'posts', 'action' => 'index')); /** * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
Router::connect('/pages/*', array('controller' => 'posts', 'action' => 'index'));
我在用户控制器中的登录操作是
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your username or password was incorrect.');
}
}
}
**调试**
当我在登录时调试时,我得到了这个
/app/Controller/UsersController.php (line 20)
object(AuthComponent) {
components => array(
(int) 0 => 'Session',
(int) 1 => 'RequestHandler'
)
authenticate => array(
(int) 0 => 'Form'
)
authorize => array(
'Actions' => array(
'actionPath' => 'controllers'
)
)
ajaxLogin => null
flash => array(
'element' => 'default',
'key' => 'auth',
'params' => array()
)
loginAction => array(
'controller' => 'users',
'action' => 'login'
)
loginRedirect => array(
'controller' => 'posts',
'action' => 'add'
)
logoutRedirect => array(
'controller' => 'users',
'action' => 'login'
)
出于某种原因,它说
loginRedirect=>数组(
“控制器”=>“posts”,
“操作”=>“添加”
)
它不是action=>index,而是unsing action=>add。为什么
Auth->redirect()返回用户登录页面或Auth->loginDirect之前登录的url
因此,如果将根路径设置为索引,它可能会起作用
Auth->redirect()返回用户登录页面或Auth->loginDirect之前登录的url
因此,如果您将根路径设置为索引,它可能会起作用。您是否设置/覆盖了Auth组件的变量?是否设置/覆盖了Auth组件的变量?