logoutRedirect()不是在CakePHP
问题描述:
工作在我的应用程序控制器I定义为logoutRedirect()不是在CakePHP
class AppController extends Controller {
public $components = array(
// 'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'admin_logins', 'action' => 'dashboard'),
'logoutRedirect' => array('controller' => 'admin_logins', 'action' => 'index'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.',
'authenticate' => array('Form' => array('fields' => array('username' => 'email', 'password' => 'password'))
)
));
..........
?>
如果会话超时而不是重定向到admin_logins/index
它重定向到users/login
,
我在应用印刷内部beforeFilter()
logoutRedirect URL控制器如下
// only allow the login controllers only
public function beforeFilter() {
$this->Auth->authorize = 'Controller';
$this->Auth->allow('index');
pr($this->Auth->logoutRedirect); die;
}
它打印如下
Array
(
[controller] => admin_logins
[action] => index
)
但它仍然重定向到users/login
有人可以在这里建议吗?
答
它是我的错。我错过了在我的AppController
中定义loginAction
。修改我的$components
后,它工作正常。
public $components = array(
// 'DebugKit.Toolbar',
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'admin_logins', 'action' => 'dashboard'),
'loginAction'=>array('controller'=>'admin_logins', 'action'=>'index'),
'logoutRedirect' => array('controller' => 'admin_logins', 'action' => 'index'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.',
'authenticate' => array('Form' => array('fields' => array('username' => 'email', 'password' => 'password'))
)
));