[size="5"]controller code[/size]
public function actionIndex() {
$posts = Post::model()->with(
array(
'author'=>array(
'select'=>'username',
),
'comments'=>array(
//if the post do not has a comment,then the post can not show ,why? I just want the comment’s status is APPROVED.
'condition'=>'comments.status='.Comment::STATUS_APPROVED,
'order'=>'comments.create_time DESC'
),
)
)->findAll("t.status=:status",array(":status"=>"".Post::STATUS_PUBLISHED));
$this->render('posts',array(
'posts'=>$posts,
));
}
[size="5"]view code[/size]
<?php foreach ($posts as $post) :?>
<?php // print_r($post);exit(); ?>
<?php echo $post->author->id.$post[‘author’][‘username’].“posts:”?><br/><br/>
title:<?php echo $post->title ;?><br/>
content :<?php echo $post->content ;?><br/><br/><br/>
评论:《<?php echo $post->commentCount ;?>》<br/><br/>
<?php foreach ($post->comments as $comment) :?>
content——》<?php echo $comment->content ;?><br/><br/>
status——》<?php echo $comment->status ;?><br/><br/>
<?php endforeach;?>
<?php endforeach;?>
[b]How to write the view to access the data? I use select but do not have a effect.
how to use the join,I use it but do not know how to show the numeric field.
who can help me write the demo code[/b]