Wednesday, July 28, 2010

Re: Invalid argument supplied for foreach() , when i use sessions

On Wed, Jul 28, 2010 at 1:17 PM, Tomfox Wiranata
<tomfox.wiranata@gmail.com> wrote:
> hi everyone,
>
> i write data in a session, which works perfectly well. but when i try
> to loop through it with foreach the error appears
>
> "Invalid argument supplied for foreach()"
>
> i figured that only arrays can be looped. here is what i did:
>
> filling the session:
>
>        $input_title = $this->data['Linkable']['notes'];
>        $this->Session->write('Linkable.title', $input_title);
>
>
> setting:
>        $this->set('linkables', $this->Session-
>>read('Linkable.title'));
>
>
> trying to echo data from my session in my view:
>
> <?php
>                foreach ($linkables as $linkable):
>                endforeach;
> ?>

You have an empty loop there.

> <span id="data"><?php echo $linkable['linkable.title']; ?></span>
>
> what did i do wrong? i thought with $this->Session-
>>write('Linkable.title', $input_title); i already created an array?

What does debug($linkables) show?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: