Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] "Non-object" fatal error when loading two models in a controller
#1

[eluser]adityamenon[/eluser]
Hi all, I have seen plenty of code examples where there are two models freely loaded and used like so:

Code:
$this->load->model('model1');
$this->load->model('model2');

$this->model1->someFunction();
$this->model2->someOtherFunction();

But when I load two models in my code, CI claims that the second model object is non-existent. This is my code:

Code:
class Main extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->model('head_section_model');
        $this->load->view('head_section', array('title' => 'Home - Site X', 'marquee' => $this->head_section_model->get_marquee()));
        $this->load->view('home_page', array('X_data' => $this->_data('X'), 'Y_data' => $this->_data('Y')));
        $this->load->view('footer');
    }
    
    private function _data($type)
    {
        $this->load->model('frontend_model', 'frontend');
        return $this->frontend->home_data($type);
    }
}

When I stop loading any one model, the code functions normally. But when I run the code above, I'm receiving an error like so:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Main::$frontend

Filename: controllers/main.php

Line Number: 21

Fatal error: Call to a member function home_data() on a non-object in C:\Program Files\wamp\www\ongoing\SiteX\application\controllers\main.php on line 21

I'm pretty sure I'm missing something fundamental... can someone please help out?


Messages In This Thread
[SOLVED] "Non-object" fatal error when loading two models in a controller - by El Forum - 06-04-2011, 02:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB