Reputation: 756
I'm getting this, but I don't understand why.:
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
I've looked at this, that and the other. But even with my simple code, it still breaks.
The Controller
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');
}
}
The Model
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;
}
}
The file is loaded successfully. If I change the class name to Menu_model_fail... I get an error, and if I change the load->model('menu_model_break') I also get an error. So I know it's loading the file correctly.
Upvotes: 0
Views: 273
Reputation: 6078
It looks like you are using the MX modular extension - you should change your controller to extend from MX_Controller instead of CI_Controller.
Upvotes: 3