[eluser]Christoffer[/eluser]
Hi,
I have a model called user_model that selects data from itself and another model called project_model. My controller dashboard.php extends from MY_Controller which loads both of these models in the constructor.
I then get the following error...
Code:
Undefined property: User_model::$project_model
Fatal error: Call to a member function fetch_projects_by_user() on a non-object in system/application/models/user_model.php on line 73
In this code...
Code:
class Dashboard extends MY_Controller
{
function __construct()
{
parent::__construct();
}
// ------------------------------------------------------------------------
function index()
{
$this->user_model->fetch_user();
$data = array(
'page_title' => 'Dashboard',
'team_name' => $this->user_model->team_name,
'projects' => $this->user_model->user_projects
);
$this->load->view('dashboard_view', $data);
}
}
That means project_model.php isn't initialized which is wierd in itself. But even wierder is that my unit test works wonders... controllers/tests/user.php can use $this->user_model->fetch_user(); without fault.
Code:
<?php
class User extends MY_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('unit_test');
}
function index()
{
$this->unit->use_strict(TRUE);
$this->user_model->fetch_user();
...
echo $this->unit->run($this->user_model->user_projects, 'is_array', 'Get users\'s projects');
echo '<p><pre>'.print_r($this->user_model->user_projects, TRUE).'</pre></p>';
}
}
Why is the success/failure not consistent over both controllers?