Problem extending library |
[eluser]sonsa[/eluser]
Hi, I am sorry if my question is stupid, i'm not an experienced user of codeigniter (not experienced in MVC either). Is it possible to extend a library in codeigniter? Here is my problem : I would like to have the following library (update.php) and use the new functions of MY_Model (extention of CI_Model) , wich i added in the application/core folder. Code: class Update extends MY_Model{ i have the following error "Class 'MY_Model' not found". However, everything is fine if i move update.php in the model folder and use it as a model. Am i doing something wrong here? Or is there an other syntax to achieve that? Thanx in advance
[eluser]the_unforgiven[/eluser]
Have you autoloaded it via autoload.php in config?
[eluser]sonsa[/eluser]
Thanks for the fast answer. I don't understand why i should autoload it if i use it in a library, when it is already autoloaded when i use it in a model. I tried autoloading it with Code: $autoload['model'] = array("MY_Model"); but i get the following error "Unable to locate the model you have specified: my_model". Can you please help me with this autoloading if it is the problem? Thanks
[eluser]Mirge[/eluser]
MY_Model.php should be in application/core/ (You did this) Update_model.php should be in application/models/ Then Update_model can extend MY_Model as normal. I just tested this. Be sure you're loading Update_model, $this->load->model('Update_model'); EDIT: I guess in your case Update_model.php should be Update.php, containing: class Update extends MY_Model { ... } Then load: $this->load->model('Update');
[eluser]sonsa[/eluser]
Hello, Yeah if i use it as a model it works with no problems at all. But i was trying to use it in a library with "Update_model" being in application/libraries/ and that's where i can't manage to make it work.
[eluser]Mirge[/eluser]
A library isn't a model. Your model belongs in models/ and your library belongs in libraries/. Libraries can USE models, but libraries aren't models. Check out these parts of user guide: http://ellislab.com/codeigniter/user-gui...w/mvc.html http://ellislab.com/codeigniter/user-gui...odels.html http://ellislab.com/codeigniter/user-gui...aries.html
[eluser]sonsa[/eluser]
Thank you. I was indeed confusing models and libraries. Thanks you all for your help and your fast answers and sorry for the trouble. |
Welcome Guest, Not a member yet? Register Sign In |