1
votes

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))

2

2 Answers

2
votes

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
}
1
votes

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).