我得到了这个,但我不明白为什么。:
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
我查看了this,that和the other。但即使使用我的简单代码,它仍然会破坏。
控制器
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;
}
}
文件已成功加载。如果我将类名更改为Menu_model_fail ...我收到错误,如果我更改了load->模型('menu_model_break'),我也会收到错误。所以我知道它正确加载文件。
答案 0 :(得分:3)
看起来您正在使用MX模块化扩展 - 您应该将控制器更改为从MX_Controller扩展而不是CI_Controller。