我得到了这个,但我不明白为什么。:
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;
}
}
文件加载成功。如果我将类名更改为 Menu_model_fail... 我会收到一个错误,如果我更改 load->model('menu_model_break') 我也会收到一个错误。所以我知道它正在正确加载文件。