On Wed, Feb 25, 2009 at 2:54 PM, Matt <[email protected]> wrote:
>
> Hello and thank you so much for your help!!
>
> Brian,
>
> I took your advice and added the userid to the session, however, I'm
> clearly doing something wrong because in the Supplier controller I
> call the session with:
> $userid = $this->Session->read('userid');
>
> However in the view, I enter echo $userid;
>
> and I receive the following error:
> Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
> line 6]

When you want to pass variables from the controller to the view, use
$this->set(). Otherwise, you're creating a variable that's outside the
view scope.

$this->set('user_id', $this->Session->read('userid'));

This will add the key & value to the $viewVars array. It'll be
available in the view because there's an extract() call in there
somewhere. In any case, it's all transparent. Use set() and then your
echo will work fine.

... unless there's no user_id in the session, of course ;-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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