另一个CodeIgniter属性未定义的问题



我得到了这个,但我不明白为什么。:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Menu::$menu_model
Filename: controllers/menu.php
Line Number: 16

Fatal error: Call to a member function get_menu() on a non-object in /home/.../modules/menu/controllers/menu.php on line 16

我已经看了这个,另一个。但是即使使用我的简单代码,它仍然会破裂。

控制器

class Menu extends CI_Controller
{
    /**
     * Constructor method
     */
    public function __construct()
    {
        parent::__construct();
    }
    function index($layout = -1)
    {
        $this->load->model('menu_model');
        // There is no $this->menu_model at this point. If I echo it out, it says property undefined as well.
        $data['menu'] = $this->menu_model->get_menu($layout);  // It fails on this line.
        $data['thisurl'] = $this->uri->uri_string();
        $this->load->view('menu.php');
    }
}

模型

class Menu_model extends CI_Model 
{
    public function get_menu($layout = -1)
    {
        $menu = array(
            0 => array('href' => '/', 'label' => 'Home', FALSE),
            1 => array('href' => '/about', 'label' => 'About', FALSE),
            2 => array('href' => '/help', 'label' => 'Help', FALSE)
        );
        return $menu;
    }
}

该文件已成功加载。如果我将类名称更改为菜单_model_fail ...我会遇到错误,如果我更改LOAD->型号('菜单_model_break'),我也会遇到错误。因此,我知道它正在正确加载文件。

看起来您正在使用MX模块化扩展名 - 您应该更改控制器以从MX_Controller而不是CI_Controller扩展。

最新更新