Instead of retrieving this information from the database on every page
load, why don't you store the user array in the session instead of
just the id.

so in your login function you would set something like this:

$user = $this->User->find(<whatever logic to find your user>);

if ($user){
$this->Session->write('CurrentUser', $user);
}


then in your views or layouts just use the session helper (make sure
you load it like var $helpers = array('Session') in your app
controller)

if ($session->check('CurrentUser')){

echo $session->read('CurrentUser.first_name');

}

Hope that helps.

By the way, the reason why your testpage() function doesn't work as
expected, is because beforeRender() is called *after* your main
controller method, and the Config class is not persistent like a
session - it gets created from scratch on every page load.

Cheers,
Adam

On Nov 30, 6:40 am, skoggins <[EMAIL PROTECTED]> wrote:
> Sorry, I'm a newbie.  I tried the code like this:
>
> App Controller
> function beforeRender() {
>
>                 if($this->Session->check('User')){
>                                 $this->set('user', 
> $this->User->findById($this->Session->read('User.id')));
>
>                                 Config::write($user, 
> $this->User->findById($this->Session->read('User.id')));
>
>                                 }else{
>                                 }
>             }
>
> Accounts Controller
>
> function testpage() {
>         Config::read($user);
>         $account_id = $user['Account']['id'];
>         $this->set('account_id', $account_id);
>
>         }
>
> but it gives me:
>
> Fatal error: Class 'Config' not found
>
> From searching the group it looks like maybe this is a component I
> need to add?  I am running Cake 1.1.18 by the way.
>
> thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to