CodeIgniter Forums
Loading a model in another model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Loading a model in another model (/thread-33159.html)



Loading a model in another model - El Forum - 08-17-2010

[eluser]Unknown[/eluser]
OK, I'm assuming you can do this but I can't get it to work.

I have Model_a that gets product information.
I have Model_b that gets shipping information.

I want to call a function from model_b into model_a

When I do something like this...
Code:
$this->load->model('Model_b');
$options = $this->Model_b->get_shipping_options();
I get this error message "Fatal error: Call to a member function get_shipping_options() on a non-object ."

Any ideas?
I've tried auto-loading the module(s) but that didn't help.

I know I'm calling the models correctly because I can do it from the controller.

Also, I had a real issue getting the db connection working in my models... I had to set a variable as the db connection in the constructor.

Any help would be great.
Dave


Loading a model in another model - El Forum - 08-17-2010

[eluser]danmontgomery[/eluser]
Code:
$CI =& get_instance();
$CI->load->model('model_b');
echo $CI-model_b->some_function();