在 cakephp2.0 中,我有domain.com但是当我注销时(url 是domain.com/logout),它被重定向到domain.com/app/login。我不希望它重定向到domain.com/app/login而是重定向到domain.com/logout。这些是我在我的 UsersController 和我的 AppController 中的代码
class AppController extends Controller {
public $helpers = array ('Html', 'Form', 'Js' => array('Jquery'), 'Session');
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authorize' => array('Controller') // Added this line
)
);
}
用户控制器
class UsersController extends AppController {
public $components = array(
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authorize' => array('Controller') // Added this line
)
);
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'logout', 'login');
$this->Auth->deny('view');
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect('http://domain.com/thankyou');
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
}
任何帮助都会很棒。谢谢。