![]() |
Problem with model class - 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: Problem with model class (/showthread.php?tid=22937) |
Problem with model class - El Forum - 09-24-2009 [eluser]Lacsap[/eluser] Hello I'm working now with Codeigniter and i must say it saves a lot of time ![]() But my problem now costs me a lot of time. First: I dont have this problem on localhost! If i upload this site to my webhoster im getting this error! And i wanna ask. Is it important to pay attention on writing: Code: $this->my_model->function(); If i call this model with a lower case first letter i'm getting error on localhost and on my webhost. But only with this model! I call all other models with lower case first letter! With a upper case first latter i dont get any errors on localhost but on my webhost. Error on webhost: Quote:Fatal error: Call to undefined method My_model::get() in .../system/application/controllers/mycontroller.php on line 29 on line 29: Code: $data['vars'] = $this->My_model->get(); the function is: Code: return $this->db->query($sql)->result(); Ive got PHP Version 5.2.11 on webhost. And PHP Version 5.3.0 on localhost. I hope that are enough imformations to solve my problem :-( THANKS ! Problem with model class - El Forum - 09-24-2009 [eluser]jedd[/eluser] Hi Lacsap and welcome to the CI forums. MY_Model (Or indeed any MY_* library) has a special meaning - it's unclear if you are aware of this, but if not, read up on the section in the user guide on extending core controllers. Generally speaking, non-extending models should be upper-case for the first letter, the rest lower. Remember this is for loading as well as for using. The filenames are all lower, and this tends to bite people oscillating between *nix and MS platforms. Problem with model class - El Forum - 09-24-2009 [eluser]Lacsap[/eluser] Thanks first. I tested some things.. i dont have my_model i just wrote it down here. ive got 2 models: food_model.php and foodbox_model.php in the file i wrote Code: class Food_model extends Model {... Code: class Foodbox_model extends Model {... i autoload them with ...'foodbox_model','food_model' i call them with Code: $this->foodbox_model Code: $this->food_model Code: $this->food_model Code: $this->foodbox_model Code: $this->Foodbox_model if i rename all words foodbox_model to box_model Code: $this->box_model could it be that two model cannot start with the same word? o.O thanks again ! Problem with model class - El Forum - 09-24-2009 [eluser]jedd[/eluser] [quote author="Lacsap" date="1253808610"] i dont have my_model i just wrote it down here. [/quote] Ahh, so you were just trying to confuse me. Quote:ive got 2 models: food_model.php and foodbox_model.php This makes sense. Quote:i autoload them with ...'foodbox_model','food_model' Why would you do that? I refer you to [url="http://ellislab.com/codeigniter/user-guide/general/models.html#loading"]the loading section of the Models page[/url] in the user guide. Quote: This is because you're loading the models wrongly. You should refer to your models with an upper-case first character. I hinted earlier that people often find problems switching between real operating systems and Microsoft operating systems. You haven't quite said so, but I'm guessing that localhost is a different operating system to whatever it is that you're talking about that isn't localhost. Would that be a fair guess? Problem with model class - El Forum - 09-24-2009 [eluser]Lacsap[/eluser] localhost is on win webhost is on linux Ok, to solve my problem i just have to load the models with upper-case first? I'll test it. thanks ! Problem with model class - El Forum - 09-24-2009 [eluser]Lacsap[/eluser] Works ! Loading with upper-case first! an calling with $this->Food_model and $this->Foodbox_model. works ! What about $this->form_validation. Should i write $this->Form_validation ? Problem with model class - El Forum - 09-24-2009 [eluser]jedd[/eluser] [url="http://ellislab.com/codeigniter/user-guide/general/libraries.html"]Using Libraries[/url] in the CI manual. Normal models have upper-case first character. Problem with model class - El Forum - 09-24-2009 [eluser]wiredesignz[/eluser] [quote author="jedd" date="1253809310"]...Why would you do that? I refer you to [url="http://ellislab.com/codeigniter/user-guide/general/models.html#loading"]the loading section of the Models page[/url] in the user guide... This is because you're loading the models wrongly. You should refer to your models with an upper-case first character...[/quote] @Jedd, the user guide does not specifically state anything about uppercase first characters when loading models, in fact the second example, loading models from a sub-directory, shows the name as lowercase. Checking the code in the CI_Loader::Model() method indicates the class variable ($name) is whatever character case you use when loading the model, it is not important. The user guide should be altered to reflect the actual code, and is misleading as it stands. EDIT: @Lacsap, I suspect your problems may be file name character case rather than loader character case. Problem with model class - El Forum - 09-24-2009 [eluser]jedd[/eluser] [quote author="wiredesignz" date="1253811187"] @Jedd, the user guide does not specifically state anything about uppercase first characters when loading models, in fact the second example, loading models from a sub-directory, shows the name as lowercase. [/quote] You're right that it's not explicitly stated. Of the four examples, three of them refer to files not located within subdirectories, and they consistently use the ucfirst format. It could be left to us to intuit the intent here. In that case, I'll happily change my earlier assertion to have a prefix of 'From my reading and interpretation of the gospel contained within the CI User Guide ...'. Quote:The user guide should be altered to reflect the actual code, and is misleading as it stands. Ah yes. The old problem. Someone should do something. What we really need is someone with a superior understanding of all things, who could rattle up some changes to the manual, and forward them on to Derek. Problem with model class - El Forum - 09-24-2009 [eluser]wiredesignz[/eluser] I have actually emailed Derek Allard in the past whenever I have discovered these things. However I think his workload is such that it takes a while for them to get his attention. |