EllisLab text mark
Advanced Search
     
Load one model from another…
Posted: 12 April 2010 07:58 AM
Joined: 2009-12-01
21 posts

Hi Guys, is it possible to call one model from another?

When I try to load model from another (something like this):

$this->load->model('Mymodel');
$this->mymodel->mymethod(); 

it alerts that “mymethod” is unknown. Same code works fine from controller.

Is there any way to do this?

Regards

 
Posted: 12 April 2010 08:26 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-11
2987 posts
$ci =& get_instance();
$ci->load->model('Mymodel');
$ci->mymodel->mymethod(); 
 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

 
Posted: 12 April 2010 08:34 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-12-01
21 posts

Thanks Phil! That’s exactly what I wanted!! Thanks a LOT!

 
Posted: 28 September 2010 04:09 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2010-08-25
17 posts

Weee thx for google seach.. just what i wanted to know to.. ^^

 
Posted: 22 September 2011 02:49 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-04-08
50 posts

Thankx this is what i wanted .

 
Posted: 02 October 2011 07:10 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-03-01
54 posts
Phil Sturgeon - 12 April 2010 08:26 AM
$ci =& get_instance();
$ci->load->model('Mymodel');
$ci->mymodel->mymethod(); 

This is the second time I’ve come across this issue (using/loading an external class or model from anything but a controller) and I’m wondering, is this the best practice for this situation? Seems wrong/unnatural.

 
Posted: 04 October 2011 10:10 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-04-28
574 posts

Well if you’re finding you need to use code across multiple models it would make more sense to put that code into a helper (or library depending on what you’re doing) and load that in your model grin

 Signature 

My new website: www.downundr.com all about Australia, check it out!

Oh, and before you post a question on this forum have you searched for a solution on google? 90% of questions on here have already been answered!!!