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

[eluser]MPress[/eluser]
[quote author="CodeOfficer" date="1193827453"]this works great for me:
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();    
    }
}
[/quote]
So you manually code wrapper methods anytime you want to utilize a method of a secondary model within your subject model? Not sure if I'm a fan. With the above load_model function that I whipped up, you can simply do the following:
Code:
$this->load_model('model2');
$this->model2->whatever();
$this->model2->another_method();
$this->model2->yet_another();


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