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