Welcome Guest, Not a member yet? Register   Sign In
Calling a model from another model?
#1

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

[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?
#3

[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
#4

[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
#5

[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.
#6

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

[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?
#8

[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.
#9

[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.
#10

[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?




Theme © iAndrew 2016 - Forum software by © MyBB