problema de admin_logout en cakephp

I have enabled admin_actions in my cakePHP project. I have a cerrar sesión() for normal employees and admin_logout() for admin logout. Both actions belong to EmployeesController.

The code inside both logout actions is the same,except for the flash message.


$this->Session->setFlash('You have been logged out of admin dashboard!','flash_success');

cerrar sesión()

$this->Session->setFlash('You have been logged out!','flash_success');

Los programas Iniciar sesión is working perfectly and destroys the session. But not the admin_logout().

For debugging, i tried this in admin_logout():

$this->Session->setFlash('You have been logged out of admin dashboard!','flash_success');

It is also working. But it still wont destroy the complete session variable. I could fix this by using normal cerrar sesión() for both admin and employee. But out of curiosity, whats going wrong here?

EDIT: Needed behavior is the destruction of session variable, then redirection with flash message. But what happens is redirection and flash message is getting displayed BUT session var is not getting destroyed!

preguntado el 31 de julio de 12 a las 12:07

What does the admin_logout action do ? instead of loggin out -

It does nothing else. Simply destroy the session and display message. -

I meant the erronomous behaviour not the needed behavior -

The error is that the session is not getting destroyed by the admin_logout(). I can still access the admin values. -

It displays the flash message and perform redirection. But its not destroying the session variable. -

3 Respuestas

Not a fix for your problem, but a slightly more elegant approach to the logout process:
Create only one logout method in your class, one without prefix. Like:

public function logout(){

Now, in all your views create a logout link explicitly nullifying the admin prefijo:

echo $this->Html->link('logout',

Respondido 31 Jul 12, 14:07

Thanks. Your method is working. But is there no fix for this issue? - Ivin

Unfortunately I don't have a fix for this issue. But to be honest: this is exactly the reason why you would use CakePHP and its features like the Auth Component. So you don't have to spend hours on ghost-bugs like these. - bart gloudemans

Hmm.. :) I wanted to use Auth component. But found it bit difficult to grasp and ended up with this! - Ivin

I completely understand :) I had the same thing. Still: take 3 hours, and dive into it. It will pay off in the end. (and DO use CakePHP 2.x because the Auth Component has become a bit more transparent compared to 1.3) - bart gloudemans

If you use 2.0 you should do




for your redirects

Respondido 31 Jul 12, 14:07

Isn't this possible only if im using Auth component? Correct me if im wrong! - Ivin

If you want to have separate flash messages for admins, you could simply use an if statement in the logout method to check whatever variable determines if the user is an admin.

        $this->Session->setFlash(__('You have been logged out of admin dashboard!','flash_success'));
        $this->Session->setFlash(__('You have been logged out!','flash_success'));

I may be missing something here but doesn't


destroy the session?

Respondido 08 Oct 13, 16:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.