Jump to content

Cake PHP view Problem


cluelessnoob

Recommended Posts

I'm trying to create a view, but whenever I load it. I get an undefined index error. My code and debug information below:

 

<? debug($posts);?>

<?=$html->link('<h1>'.$posts['Post']['name'].'</h1>','/posts/read/'.$posts['Post']['id'],null,null,false);?> 
<p>Author: <?=$posts['User']['name'];?>
<p>Date Published: <?=$time->nice($posts['date']);?></p>
<hr/> 

 

Array
(
    [0] => Array
        (
            [Post] => Array
                (
                    [id] => 1
                    [name] => How to Skateboard
                    [date] => 2009-06-28 23:01:00
                    [content] => A simple detailed how to tutorial for skateboarding.
                    [user_id] => 1
                )

            [user] => Array
                (
                    [id] => 1
                    [name] => Bartman
                    [email] => bsimpson@fox.com
                    [firstname] => Bart
                    [lastname] => Simpson
                )

            [comment] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [name] => Great Article
                            [content] => I learned alot
                            [post_id] => 1
                        )

                    [1] => Array
                        (
                            [id] => 2
                            [name] => Good for begginers
                            [content] => OK for beginners, but lacking for more advanced people
                            [post_id] => 1
                        )

                )

        )

    [1] => Array
        (
            [Post] => Array
                (
                    [id] => 2
                    [name] => How to make beer
                    [date] => 2009-06-28 23:31:00
                    [content] => This is a detailed article on how to make beer
                    [user_id] => 2
                )

            [user] => Array
                (
                    [id] => 2
                    [name] => Duffman
                    [email] => hsimpson@fox.com
                    [firstname] => Homer
                    [lastname] => Simpson
                )

            [comment] => Array
                (
                    [0] => Array
                        (
                            [id] => 3
                            [name] => Glughhhhh Beer
                            [content] => No beer and no TV make me something, something
                            [post_id] => 2
                        )

                )

        )

)

 

Here's the errors:

 

Notice (8): Undefined index:  Post [APP\views\posts\read.ctp, line 4]

 

 

Notice (8): Undefined index:  User [APP\views\posts\read.ctp, line 5]

 

Notice (8): Undefined index:  date [APP\views\posts\read.ctp, line 6]

 

Link to post
Share on other sites

is

 

<? debug($posts);?>

<?=$html->link('<h1>'.$posts['Post']['name'].'</h1>','/posts/read/'.$posts['Post']['id'],null,null,false);?>
<p>Author: <?=$posts['User']['name'];?>
<p>Date Published: <?=$time->nice($posts['date']);?></p>
<hr/> 

 

from read.ctp?  Is that all the code in the view?  I'm assuming it is not read.ctp only because you are linking to read.ctp with the post id.  Please post all the relevant code.

Link to post
Share on other sites

$posts is an array and you need to loop through it.  Something like

 


foreach($posts as $post) {
echo "<h1>" . $html->link($post['Post']['name'], '/posts/view/' . $posts['Post']['id']) ?> . "</h1>"
echo "<p>Date Published: " . $time->nice($posts['Post']['date']) . "</p>";
<hr/> 
}

 

etc...

Link to post
Share on other sites
  • 10 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.