CodeIgniter Forums
Calling a model from another model? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Calling a model from another model? (/showthread.php?tid=9356)

Pages: 1 2 3


Calling a model from another model? - El Forum - 06-22-2008

[eluser]mattalexx[/eluser]
What would be the syntax for calling another model's methods from within a model?


Calling a model from another model? - El Forum - 06-22-2008

[eluser]Tomas Sundvall[/eluser]
Have you try to just load the model in the constructor, and then use it the same way as if it was in a controller?


Calling a model from another model? - El Forum - 06-22-2008

[eluser]mattalexx[/eluser]
[quote author="Tomas Sundvall" date="1214206315"]Have you try to just load the model in the constructor, and then use it the same way as if it was in a controller?[/quote]
Yes, but it didn't work:
Code:
// Get item_images
$this->load->model('Item_Image_model');
$select = $this->Item_Image_model->get_select(); // <-- Undefined property: Item_model::$item_image_model



Calling a model from another model? - El Forum - 06-22-2008

[eluser]Randy Casburn[/eluser]
hey mattalexx, this is a case issue -- follow me: don't be afraid to dive into the code a little to answer your own questions. It seems you've got the skills in your tool box.

So in the libraries/loader.php file around line 108 you'll find the model() method. You'll see in the code at line 153 your file name is shifted to lower case and the file system is searched for it. All is well as it is found and the model is loaded up. The problem appears down at line 175 where the PHP ucfirst() function is used to register your model name with CI. So when you attempt to use it is complains.

Try shifting your file name to ucfirst() and class declarations to ucfirst() and see if that fixes things up.

Randy


Calling a model from another model? - El Forum - 06-22-2008

[eluser]Colin Williams[/eluser]
There are a few conventions CI uses for naming models, libraries, controllers, etc. Stick to them to avoid these problems. You can find these conventions by reading through the user guide.


Calling a model from another model? - El Forum - 06-22-2008

[eluser]Randy Casburn[/eluser]
it was just less fun to say that ;-)


Calling a model from another model? - El Forum - 06-23-2008

[eluser]mattalexx[/eluser]
[quote author="Colin Williams" date="1214216890"]There are a few conventions CI uses for naming models, libraries, controllers, etc. Stick to them to avoid these problems. You can find these conventions by reading through the user guide.[/quote]

Having a problem figuring this one out, too. What's your usual practice?


Calling a model from another model? - El Forum - 06-23-2008

[eluser]xwero[/eluser]
The filenames should be in lowercase so the underscore between the words form is the most readable. The only exception are the extended models/controllers/libraries.

You can load the model with lowercase letters and use it with lowercase letters even if you uppercased the begin letters of the model name.


Calling a model from another model? - El Forum - 06-23-2008

[eluser]Randy Casburn[/eluser]
@mattelex

Models: Look for Anatomy of a Model

Libraries: Look for (uh...) Naming Conventions


Come on Dude...this is one of the finest User Guides on the planet. Try a little harder.


Calling a model from another model? - El Forum - 06-23-2008

[eluser]mattalexx[/eluser]
[quote author="Randy Casburn" date="1214256399"]@mattelex

Models: Look for Anatomy of a Model

Libraries: Look for (uh...) Naming Conventions


Come on Dude...this is one of the finest User Guides on the planet. Try a little harder.[/quote]

Why are you being so condescending?

1. Go here
2. Ctrl+F for "Blogmodel"
3. Ctrl+F for "User_model".

Am I missing something here or is that a discrepancy in the docs?