The issue you're running into is in the default index view and
controller action you have recursive set to 0 for speed reasons. A
quick fix would be to set that value higher to retrieve comments
associated with posts.

A better solution would be to use the Containable behavior and limit
it to just 3 comments and what fields you intend on showing.

Use those Google skills and checkout the cookbook docs for
containable, there's an example that's almost exactly what you need
written for you.

Good luck,
Nick
On Jun 19, 7:29 am, Paul Wheatley <[email protected]> wrote:
> Hi,
>
> Can anyone tell me how i can show comments for a post on the index.ctp page?
>
> Basically what i am trying to do it create a panel under each post title that 
> will display the comments.  In this format...
>
> Post A title
> Post A snippet content
>         Comment 1
>         Comment 2
>         Comment 3
>
> Post B title
> Post B snippet content
>         Comment 1
>         Comment 2
>         Comment 3
>
> Post C title
> Post C snippet content
>         Comment 1
>         Comment 2
>         Comment 3
>
> etc...
>
> But when i use this code to display the comments (under each post title)...
>
>                 <?php
>                         $i = 0;
>                         foreach ($course['Comment'] as $comment):
>                         $class = null;
>                         $say = $comment['say_id'];
>                         $usrid = $comment['user_id'];
>                         if ($i++ % 2 == 0) {
>                                 $class = ' class="altrow"';
>                         }
>                 ?>
>                                 <strong><?php echo 
> $comment['name'];?></strong>
>                                 <p><?php echo $comment['content'];?></p>
>                                 <p>Published by <?php echo 
> $comment['commenter'];?> on <?php echo $comment['created'];?></p>
>                 <?php endforeach; ?>
>
> I get the following error on the page...
>
> Notice (8): Undefined index:  Comment [APP/views/posts/index.ctp, line 29]
> I am guessing that this is because the index page hasn't pulled in the 
> Comment controller so i looked at the view portion of the posts controller 
> and i can't find how/where it pulls in use of the comment controller.  I am 
> throughly confused.
>
> I have googled heavily for the answer and i can't find anything, i can only 
> assume that it is a simple solution that no one ever (apart from me) has 
> gotten stuck with it before.
>
> Paul

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to