My Logout function is working very well with only return $this->redirect($this->Auth->logout());.
But how could I make a logout function with a Flash message? I tried this function. It doesn't work. I'm always login and it doesn't show me message:(
public function logout() {
if ($this->Auth->user('logged_in')) {
$this->Session->setFlash(__('you are logout'), 'default', array('class' => 'alert alert-success'));
return $this->redirect($this->Auth->logout());
} else {
$this->Session->setFlash(__('you aren\'t logout, Please, try again'), 'default', array('class' => 'alert alert-danger'));
}
}
Inside the documentation says that if you want to create a custom message do by in /app/View/Elements. If you want your personalized message is not the way to go.
in your /app/View/Elements/defaul.ctp
$this->Session->setFlash(__('you are logout'), 'default', array('class' => 'alert alert-success'));
afte in your cont roller
public function logout() {
if ($this->Auth->user('logged_in')) {
$this->Session->setFlash('something', 'default');
return $this->redirect($this->Auth->logout());
} else {
$this->Session->setFlash(__('you aren\'t logout, Please, try again'), 'default', array('class' => 'alert alert-danger'));
}
}
you could also do it through a component