Hi, I am really new to Cake and have been through some of the
tutorials.
I have found it a little hard at this stage to work out how to achieve
some usually quite simple things. I did try and find a good example of
this but with no luck.
For example; the Posts tutorial. I wanted to output a list of Posts
(the parent) with the titles of related comments (the childs)
underneath them.
e.i.
Post 1
Comment 1
Comment 2
Comment 3
Post2
Comment 1
Comment 2
Post 3
Comment 1
Comment 2
I have set Deug to level 2 and I can see that the queries are being run
but cant figure out how to loop through the children!
Here is what I have:
class PostsController extends AppController
{
var $name = 'Posts';
var $scaffold;
function index()
{
$this->set('posts', $this->Post->findAll());
$this->set('comments', $this->Comment->hasMany());
}
}
class Post extends AppModel
{
var $name = 'Post';
var $hasMany = array('Comment' =>
array('className' => 'Comment',
'conditions' => '',
'order' => 'Comment.created DESC',
'limit' => '',
'foreignKey' => 'posts_id',
'dependent' => true,
'exclusive' => false,
'finderSql' => ''
)
);
}
It would appear that I have things OK up to here. How should I
reference the Comments data from within the index.thtml though?
Am I on the right track with my model and controller?
I didnt post that here as it would bloat this page! Any guidance
would be very appreciated.
ski.nalicio.us
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---