Reputation: 5094
PLEASE HELP....I AM A NEWBIE
I have 2 tables PAGE and COMMENT.
Page table has columns
$id
user_id
$content
Comment table has columns
$id
$user_id
$page_id
$date_entered
$comment The comment column consist of an array of comments as one user can have many comments
In the Page model the relation in the relation() is defined as
'comments' => array(self::HAS_MANY, 'Comment', 'page_id'),
Now in the PageControllor.php,I have defined this query in the actionView()
$page = Page::model()->with('user','comments')->findByPk($id);
Now my question is
** how can i get the result of this query in $result so that i could pass it to the view page as
$this->render('view',array(
'model'=>$this->loadModel($id),'result'=>$result))
Upvotes: 1
Views: 145
Reputation: 1684
You should pass the comments to the view file as follows,
$this->render('viewname', array(
'comments'=>$page->comments
));
And in your view file, you should do the following,
foreach($comments as $c){
//Display the comment
}
Upvotes: 2
Reputation: 437534
You will pass the variable $page
to the view and from inside the view access the comments with $page->comments
(this will be an array).
Upvotes: 1