【发布时间】:2015-12-08 18:27:08
【问题描述】:
我正在努力更好地了解 CI 的工作原理。
这是我的第一张桌子,app_news:
id / name
我的第二个是app_news_cmets:
id / id_news / comment
我用来显示新闻信息的模型是:
public function get_news($where = array()) {
return $this->db->select('*')
->from('app_news')
->where($where)
->get()
->result();
}
我用来计算新闻的 cmets 的模型是:
public function count_comment($id_news) {
return (int) $this->db->where(array('id_news' => $id_news)
->count_all_results('app_news_comments');
}
我的第一个解决方案是在我的视图上打印一个 foreach 并将 count_comment 函数放入循环中以计算我有多少 cmets 但是我不会尊重 MVC 模式。我该怎么做?
【问题讨论】:
标签: php codeigniter activerecord