Could not find 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: Could not find Model (/showthread.php?tid=32181) |
Could not find Model - El Forum - 07-15-2010 [eluser]biber90[/eluser] Hey Codeigniter Community, today I stumbled about a very odd problem: I have created a model called "test_model" with a function in it. If I load this model in another models function, the function of the test_model works fine. But when I want to connect to the database automatically (so I add 'database' to the autoload array), than I get an error that the function in the test_model could not be find. I can not appreciate it. Where is the connection between the database library and models? Quote:A PHP Error was encountered Thanks for your help! Could not find Model - El Forum - 07-15-2010 [eluser]danmontgomery[/eluser] I don't understand... You're calling test_model as a member of another class from within the test_model class? You may need to post some code. Could not find Model - El Forum - 07-15-2010 [eluser]jedd[/eluser] [quote author="biber90" date="1279213455"] I have created a model called "test_model" with a function in it. [/quote] More information - what's the filename, what's the model's actual name. Quote:If I load this model in another models function, the function of the test_model works fine. Don't do this. It suggests your design is flawed. Consider extending the Model (MY_Model) or shifting common functionality into a library (or even helper - though if you're trying to do DB stuff, a library is preferable). Quote:But when I want to connect to the database automatically (so I add 'database' to the autoload array), than The error message you showed isn't the same as 'test_model could not be found'. Did you see other error messages that you didn't post? Quote:I can not appreciate it. Where is the connection between the database library and models? The user guide goes through this in some detail - I'd recommend you re-read the sections on libraries and models. The [url="/wiki/FAQ"]FAQ[/url] also contains an answer to this question (okay - so I just put it in there - but only because I'm getting bored of the number of people who post questions without scanning the forums first for an existing answer. Have a read through my [url="/wiki/How_to_ask_a_good_question/"]guide to asking good questions[/url] when you have a minute. Could not find Model - El Forum - 07-15-2010 [eluser]biber90[/eluser] Ok, i am using a model called 'buildings_model'. In this model is a function called showAll(); Code: <?php I also have another model called 'update_model'. Code: <?php The controller loads the database, both models and calls the function test. Everything ok so far. But when I add the database to the autoload array, I get the error above. Could not find Model - El Forum - 07-15-2010 [eluser]jedd[/eluser] [quote author="biber90" date="1279217079"]Ok, i am using a model called 'buildings_model'. [/quote] I'll ask again - what is/are the filename(s)? Can you also quote the section of your autoload.php file where you're trying to autoload the model(s)? Actually, what do you mean by 'auto-loading the database'? Quote: Don't close PHP tags in your models or controllers. Could not find Model - El Forum - 07-15-2010 [eluser]biber90[/eluser] The filenames are like the name of the classes (buildings_model.php, update_model.php). The section of my autoload.php is: $autoload['libraries'] = array('database', 'session'); I don't want to autoload the models. I only want to autoload the library database, without getting the above error. Could not find Model - El Forum - 07-15-2010 [eluser]jedd[/eluser] [quote author="biber90" date="1279223769"]The filenames are like the name of the classes (buildings_model.php, update_model.php). [/quote] Good. I wanted to rule out case sensitivity issues. Quote:The section of my autoload.php is: This looks normal. I don't think autoloading the database library is the root cause of your problem. The error cites line 148 - perhaps you could show us that region - of the file models/test_model.php. The error seems to be coming from a different file, though - models/calling_model.php. If you comment-out the loading of those two models, does your database library load okay? Could not find Model - El Forum - 07-15-2010 [eluser]biber90[/eluser] I found the solution to my problem I included the models like this: $this->load->model(array('update_model', 'buildings_model')); But when the update_model gets initialized it can not find the function in the building_model. So i changed the order of them. Another careless mistake, sorry! And thanks for your help Great forums. |