【发布时间】:2012-12-23 10:16:55
【问题描述】:
当我尝试编写和运行 Code Igniter 教程时,它会抛出这个错误:
Call to undefined method News_model::get_news() in application\controllers\news.php on line 21
这是第 21 行:
$data['news'] = $this->news_model->get_news($slug);
mews 模型
<?php
class News_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this ->db->get('news')
return $query->result_array();
}
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
}
【问题讨论】:
-
你在 News_model 上定义了 get_news 方法了吗?是公开的吗?
-
发布
news_model。没有它,我们将在黑暗中拍摄 -
一旦你调用了
$this->load->model('news_model'),它就在单例中。在其中定义的任何公共方法都是可用的。我们确实需要查看您的模型,或者至少它的构造函数(如果它有一个)和方法的定义。
标签: php codeigniter controller