Welcome Guest, Not a member yet? Register   Sign In
Loading models within models
#1

[eluser]bhogg[/eluser]
Am having an odd problem and hoping someone can figure out why it might be happening!

On an old codebase just upgraded to 1.7.2 (still using old validation, etc), I've got a couple models in the appropriate locations (application/models/opportunities_model.php, application/models/students_model.php), which I've modified from their original code in order to try and rule out interference in debugging the issue:

Code:
class Opportunities_model extends Model {

    function Opportunities_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
...

    function get($id)
    {
        echo "<p>getting session from opportunities_model...</p>";
        $this->load->model("sessions_model");
        echo print_r($this->sessions_model->get(9));
        return;

        ...
    }

    ...
}

class Students_model extends Model {
    
    function Students_model()
    {
        // Call the Model constructor
        parent::Model();
    }    

    ...

    function get($id)
    {
        echo "<p>getting session from students_model...</p>";
        $this->load->model("sessions_model");
        echo print_r($this->sessions_model->get(9));
        return;
    }
}

Then, in a controller:


Code:
...

    function edit($opportunities_id)
    {
        $this->load->library('validation');
        $this->load->model('opportunities_model');
        $this->load->model('students_model');
        
        $this->students_model->get("0251117");
        
        $this->opportunities_model->get($opportunities_id);
        ...
    }

Visiting myurl.com/opportunities/edit/699 shows:
Quote:getting session from students_model...
Array ( [0] => Array ( [id] => 9 [name] => September 2010 Selections [hide] => 0 [current] => 1 [allowedit] => 0 [allow_contact_view] => 1 [selection_est] => 2010-09-27 18:00:00 [created_est] => 0000-00-00 00:00:00 [obslt_est] => ) ) 1

getting session from opportunities_model...
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Opportunities_model::$sessions_model

Filename: models/opportunities_model.php

Line Number: 493

Fatal error: Call to a member function get() on a non-object in /private/var/www/community/system/application/models/opportunities_model.php on line 493

Why on earth would one model be able to load another unrelated model from within and not the other?

Thanks for any insights!


Messages In This Thread
Loading models within models - by El Forum - 04-14-2011, 08:49 AM
Loading models within models - by El Forum - 04-14-2011, 11:31 AM
Loading models within models - by El Forum - 04-14-2011, 12:27 PM
Loading models within models - by El Forum - 04-14-2011, 02:57 PM
Loading models within models - by El Forum - 04-14-2011, 03:19 PM
Loading models within models - by El Forum - 04-15-2011, 12:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB