Welcome Guest, Not a member yet? Register   Sign In
Loading a model within a model.
#19

[eluser]CodeOfficer[/eluser]
Really I don't understand why it would be so complicated, the code below as I said before works fine. After a $this->CI =& get_instance(); you can load them wherever you want, in the constructor or in a method. The loader only returns a reference to a model if its already been loaded before, its not not a waste of resources in the least.

I would never want to load a model in a constructor if only 2 of 12 methods in my class used that model. its silly.

Code:
class MyModel extends Model
{
    private $CI;
    
    function MyModel()
    {
        parent::Model();
        $this->CI =& get_instance();    
    }
    
    function whatever()
    {
        $this->CI->load->model('model1');    
        $this->CI->model1->method1();
    }
    
    function woot()
    {
        $this->CI->load->model('model2');    
        $this->CI->model2->method2();    
    }
}


Messages In This Thread
Loading a model within a model. - by El Forum - 10-30-2007, 04:59 PM
Loading a model within a model. - by El Forum - 10-30-2007, 05:26 PM
Loading a model within a model. - by El Forum - 10-30-2007, 05:35 PM
Loading a model within a model. - by El Forum - 10-30-2007, 08:51 PM
Loading a model within a model. - by El Forum - 10-30-2007, 11:44 PM
Loading a model within a model. - by El Forum - 10-31-2007, 05:28 AM
Loading a model within a model. - by El Forum - 10-31-2007, 12:08 PM
Loading a model within a model. - by El Forum - 10-31-2007, 12:11 PM
Loading a model within a model. - by El Forum - 10-31-2007, 01:45 PM
Loading a model within a model. - by El Forum - 10-31-2007, 01:54 PM
Loading a model within a model. - by El Forum - 10-31-2007, 02:26 PM
Loading a model within a model. - by El Forum - 10-31-2007, 02:27 PM
Loading a model within a model. - by El Forum - 10-31-2007, 03:58 PM
Loading a model within a model. - by El Forum - 10-31-2007, 04:10 PM
Loading a model within a model. - by El Forum - 10-31-2007, 04:26 PM
Loading a model within a model. - by El Forum - 10-31-2007, 05:03 PM
Loading a model within a model. - by El Forum - 11-02-2007, 04:34 AM
Loading a model within a model. - by El Forum - 11-02-2007, 07:14 AM
Loading a model within a model. - by El Forum - 11-02-2007, 12:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB