cluelessnoob Posted July 11, 2009 Share Posted July 11, 2009 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 (: Undefined index: Post [APP\views\posts\read.ctp, line 4] Notice (: Undefined index: User [APP\views\posts\read.ctp, line 5] Notice (: Undefined index: date [APP\views\posts\read.ctp, line 6] Quote Link to comment https://forums.phpfreaks.com/topic/165621-cake-php-view-problem/ Share on other sites More sharing options...
jcombs_31 Posted July 11, 2009 Share Posted July 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165621-cake-php-view-problem/#findComment-873628 Share on other sites More sharing options...
cluelessnoob Posted July 11, 2009 Author Share Posted July 11, 2009 This is the read.ctp, the link was wrong. It should have been pointing to view. So this is the relevant code. You just caught one of my many errors. Quote Link to comment https://forums.phpfreaks.com/topic/165621-cake-php-view-problem/#findComment-873739 Share on other sites More sharing options...
jcombs_31 Posted July 11, 2009 Share Posted July 11, 2009 $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... Quote Link to comment https://forums.phpfreaks.com/topic/165621-cake-php-view-problem/#findComment-873776 Share on other sites More sharing options...
veenes2010 Posted May 19, 2010 Share Posted May 19, 2010 hey dude this is very useful information exactly what i was looking for, i was stuck when i need to create multiple forms for the same page…noe i can place different forms in separate views and select the views accordingly based on condition ===================== Cosmetic Surgery| Boob Job Quote Link to comment https://forums.phpfreaks.com/topic/165621-cake-php-view-problem/#findComment-1060407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.