It seems like $var isn't really the array you posted, how did you
output it and did you really output $var? You can use print_r($var) or
var_dump($var) to output it.

The array should look like the following and you can only directly
access an array through the existing indices:

Array ( ['Post'] => Array ( [id] => 3 [title] => Title strikes back
[body]
=> This is really exciting! Not. [created] => 2008-06-29 21:35:37
[modified] => 2008-06-30 22:00:25 ) )

On 2 Jul., 10:20, Latoune - Newbie <[EMAIL PROTECTED]> wrote:
> Thanks for this feedback. After two days I found the solution:
>
>             if ($this->Post->findByTitle($this->data['Post']['title']))
>                     {
>                                 $var = 
> $this->Post->findByTitle($this->data['Post']['title']);
>                                 $this->redirect('/posts/view/' . 
> $var['Post']['id']);
>                         }
>
> and it worked.
>
> I also did:
>         $var = $this->Post->findByTitle($this->data['Post']['title']);
>                 if (!empty($var))
>                 {
>                         $this->redirect('/posts/view/' . $var['Post']['id']);
>                 }
>
> which works too but is cleaner. please note that
>
> $var['Post']['id'] works
> $var[0]['id'] does not work.
>
> If someone can let me know why? it woudl be appreciated.
>
> Thanks
>
> On Jul 2, 12:09 am, schneimi <[EMAIL PROTECTED]> wrote:
>
> > $var[0]['id'] is the correct syntax for the array you posted, are you
> > sure it is really the content of $var? Not rather $var['Post'][0]
> > ['id']?
>
> > Btw, you shouldn't do the findByTitle twice, this is better:
>
> > $var = $this->Post->findByTitle($this->data['Post']['title']);
>
> >  if      (!empty($var))
> >  {
> >          $this->redirect('/posts/view/' . $var[0]['id']);
> >  }
>
> > Hope this helps,
>
> > Michael
>
> > On 1 Jul., 20:41, Latoune - Newbie <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
> > > I am a newbie so please sorry if the question seems basic but I cannot
> > > find this solution:
>
> > > I have created a Posts table with the following attributs:
> > > id,
> > > title,
> > > bodytext,
> > > etc.
>
> > > I now want to test the findby<fieldame> function so I create a
> > > function called         "findbytitle" in my posts_controller.php script. 
> > > This
> > > function takes in a form input to retrieve the row in the table that
> > > has the same title. I want then to call a "view" with the id matching
> > > the title. I did:
>
> > > ...
> > > function findbytitle($id = null)
>
> > > if      ($this->Post->findByTitle($this->data['Post']['title']))
> > > {
> > >         $var = $this->Post->findByTitle($this->data['Post']['title']);
> > >         $this->redirect('/posts/view/' . $var);
>
> > > }
>
> > > ...
>
> > > but it does not work
>
> > > $var is an array. in my case it is:
> > > Array ( [0] => Array ( [id] => 3 [title] => Title strikes back [body]
> > > => This is really exciting! Not. [created] => 2008-06-29 21:35:37
> > > [modified] => 2008-06-30 22:00:25 ) )
>
> > > I then tried:
> > > ...
> > > function findbytitle($id = null)
>
> > > if      ($this->Post->findByTitle($this->data['Post']['title']))
> > > {
> > >         $var = $this->Post->findByTitle($this->data['Post']['title']);
> > >         $this->redirect('/posts/view/' . $var[0]['id']);
>
> > > }
>
> > > ...
>
> > > but I got:
>
> > > Notice: Undefined index: 0 in C:\Program Files\EasyPHP 2.0b1\www\cake
> > > \app\controllers\posts_controller.php on line 66
>
> > > I do not know how to retrieve the value of the id from the array.
>
> > > I am struggling. Can someone tell mw what the right syntax is or what
> > > instructions I should be using!
>
> > > Many thanks
--~--~---------~--~----~------------~-------~--~----~
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