模型/ blogmodel.php:
class Blogmodel extends CI_Model {
public function get_recent_post($num){
$query = $this->db->get('wdr_blog_post', $num);
return $query->result();
}
}
控制器/ blog.php的:
class Blog extends CI_Controller {
public function index(){
$this->load->model('blogmodel');
$posts = $this->Blogmodel->get_recent_post(5);
}
}
错误:
遇到PHP错误
严重性:注意
消息:未定义属性:Blog :: $ Blogmodel
文件名:controllers / blog.php
行号:7
致命错误:在第7行的G:\ server \ htdocs \ xyz \ app \ controllers \ blog.php中的非对象上调用成员函数get_recent_post()
答案 0 :(得分:1)
猜猜......
class Blog extends CI_Controller {
public function index(){
$this->Blogmodel = $this->load->model('blogmodel');
$posts = $this->Blogmodel->get_recent_post(5);
}
}