Wednesday, September 2, 2009

Re: Learning cakePHP debugging

$activeUser = $this->User->find(array($this->Auth->user('id')));
Not sure I understand why you set the active user with this line:
as $this->Auth->user() should contain everything you need from the
user model.

After a user is logged in you never tell the auth component that the
user has logged out. So even after logging out this->Auth->user
contains a valid user.
I suppose after you've logged out and you click on your login link
from the home page it probably never asks for new credentials and goes
straight to the start page.


At the end of your logout you should be calling:
$this->redirect($this->Auth->logout());

That will clear the $this->Auth->user() object and you can test for it
via:
if($this->Auth->user())

You'll want to set in your beforeFilter:
$this->Auth->logoutRedirect = array('controller' => 'pages', 'action'
=> 'home');

which should take care of your redirect to the home page when a user
logs out.

On Sep 2, 7:54 am, McScreech <scre...@sympatico.ca> wrote:
> @Martin, thanks. debug($activeUser); returns the type of output I was
> expecting.
>
> @abc, I'll look into the php version also.
>
> Now on to my problem, once I actually stopped to _read_ the debug
> output I realized that the $activeUser variable is NOT CHANGING when I
> log out and log back in again. In addition to the partial setup that I
> described above, here are the login and logout functions in my
> users_controller.php:
>
>         function login() {
>                 if( $this->Auth->user() ) {
>                         // Redirect to start page.
>                         $this->redirect( array('controller' => 'pages', 'action' =>
> 'start') );
>                 }
>         } // end login()
>
>         function logout() {
>                 $this->Session->destroy();
>                 $this->Session->SetFlash(__('Successfully logged out', true));
>                 $this->redirect( array('controller' => 'pages', 'action' =>
> 'home') );
>         } // end logout()
>
> I am using php 5.2.9-1 and cakePHP 1.2.3.8166.
>
> Thanx again, McS.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: