在Codeigniter上需要帮助来解决Controller和Model上的错误

时间:2014-03-29 15:21:27

标签: php codeigniter model controller

模型/ 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()

1 个答案:

答案 0 :(得分:1)

猜猜......

class Blog extends CI_Controller {
    public function index(){
        $this->Blogmodel = $this->load->model('blogmodel');
        $posts = $this->Blogmodel->get_recent_post(5);
    }
}