[eluser]hitraj47[/eluser]
[quote author="deep_sheera" date="1338531590"] $data['pages_list'] = $this->page_model->get_page_list_admin(); ..... try to call another function and then check is really page_model not load here or is there any other problem in that function ..[/quote]
I made a function called test() in my page_model.php:
Code:
public function test() {
$test = 'test';
return $test;
}
Then I assigned $data['pages_list'] to $this->page_model->test(); and I got the same error, this time PHP is saying
Fatal error: Call to a member function test() on a non-object
Then when I changed it back to
Code:
$data['pages_list'] = $this->page_model->get_page_list_admin();
I get the same error as before, with PHP saying:
Fatal error: Call to a member function get_page_list_admin() on a non-object
I even changed it to one of the functions that already existed in the page_model that works in my Page controller and I still get the same error.
EDIT:
Wow I just fixed it... In my admin.php controller I had:
Code:
public function __construct() {
parent::__construct();
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('template');
$this->load->model('page_model');
}
As you can see I load the page_model last... I moved that up to the top so now it says:
Code:
public function __construct() {
parent::__construct();
$this->load->model('page_model'); // page model loads first
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('template');
}
This fixed the errors... I don't know why this worked, can someone explain it? Should models/helpers and libraries etc that are loaded in the constructor be loaded in a certain order?