此CodeIgniter代码有什么问题


What is wrong with this CodeIgniter code?

我正试图将应用程序的几个函数从CodeIgniter应用程序移植到另一个现有的CodeIgnitor应用程序。两个应用程序本身都运行得很好,但当我添加这个东西时,会出现以下错误:

致命错误:在第7行的…''application''core''MY_Model.php中的null处调用成员函数order_by()

在这个问题中,我删除了与错误无关的部分,以简化代码。

//MY_Model.php模型文件

<?php
class MY_Model extends CI_Model {
    protected $_order_by = '';
    public function get(){
        $this->db->order_by($this->_order_by);
    }
}

//article_m.php模型文件

<?php
class Article_m extends MY_Model
{
    protected $_order_by = 'pubdate desc, id desc';
}

//frontend.php控制器文件

<?php
class Frontend extends MY_Controller
{
    function __construct()
    {
    $this->load->model('article_m');  
    }
    function index()
    {
    $this->article_m->get();
    }
}

请帮忙。非常感谢。

无论何时调用任何$this->db ...,都必须确保加载database库。在application'config'autoload.php中检查以下内容:

$autoload['libraries'] = array('database');