On Wed, Feb 16, 2011 at 7:46 PM, barricades <[email protected]> wrote:
> Thanks for the reply. I'm learning :)

OK, here's another tip: you don't need to save the email to the
session. Auth already does that for you. :-)

When a user logs in, every column in the users table is stored in the
session. There two ways to get that info.

First, AuthComponent has a method, user(), that returns the value of
whatever field you name. So, if the code is in a controller, you'd do:

$email = $this->Auth->user('email');

Second, if the code is in a view:

echo $this->Session->read('Auth.User.email');

Note the differences. In the second version, you're fetching the info
directly from the SessionHelper, which has it stored under the
'Auth.User' key (case is important). In the first version, you're
using the component's shorthand method, which essentialy does the same
thing.

What you were orginally doing is still useful in cases where you want
to store data from some associated table in the session.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to