我是Codeingiter的新手,我正在建立一个简单的博客.
在Post表中,我有"id,cat_id,title,content"...在类别平板电脑中我有"id,name"...
要显示帖子,
我使用以下函数从模型内的POST中获取内容...
function get_posts(){
$query = $this->db->get('post');
return $query->result();
}
Run Code Online (Sandbox Code Playgroud)
然后我加载视图文件以显示帖子...上面的函数只获取CATEGORY ID,但我需要类别名称...所以我需要从视图文件调用模型...我认为调用模型是不合逻辑的从视图...是否有任何解决方案???
请帮我...
谢谢
小智 10
你可以用这个:
$ci =&get_instance();
$ci->load->model(your model);
$ci->(your model)->(your function);
Note: You have to call your model in your controller.Its working fine
Run Code Online (Sandbox Code Playgroud)