In cakephp2.0, I have domain.com but when I logout (url is domain.com/logout), it is redirected to domain.com/app/login. I dont want it to redirect to domain.com/app/login but instead redirect to domain.com/logout. These are the codes I have in my UsersController & my 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
)
);
}
Userscontroller
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());
}
}
Any help would be great. Thanks.
I ended up using this in my logout() function