如果forumController 中actionView 要从多张数据表中
1 取得当前forum 帖子总数
2 当前forum 中的前20个帖子
是不是要 $forum=$this->loadForumModel();
$topics=$this->loadTopicModel();
还是二个合成一个???
如果forumController 中actionView 要从多张数据表中
1 取得当前forum 帖子总数
2 当前forum 中的前20个帖子
是不是要 $forum=$this->loadForumModel();
$topics=$this->loadTopicModel();
还是二个合成一个???
我知道了 在关系中定义2个就可以全部得到
可是 关系中定义了3个 我只希望运行前2个 咋办?
public function relations()
{
return array(
'topics'=> array(self::HAS_MANY,'Topic','forum_id'),
'topicCount'=> array(self::STAT,'Topic','forum_id'),
'公告'=>array('self::HAS_MANY','公告','forum_id'),
);
}
$topics = Forum::model()->with(‘topics’)->findAll();
$topicNum = Forum::model()->with(‘topicCount’)->findAll();
原来是这样的
把 $topics->topics $topicNum ->topicCount 传到试图老觉得不好 怎么把2个合成一个?
你将$model传给视图。
用的时候,直接写$model->topics,和$model->topicCount即可