Model library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Model library (/showthread.php?tid=23244) Pages:
1
2
|
Model library - El Forum - 10-04-2009 [eluser]Unknown[/eluser] I have made a model library for codeigniter. It is based on the article http://maestric.com/doc/php/codeigniter_models The code is on my blog http://csotelo.blogspot.com/2009/10/model-library-for-codeigniter-php-if.html Please check and test it regards Model library - El Forum - 10-05-2009 [eluser]eoinmcg[/eluser] Thanks for this Carlos. I'll take a look and let you know if I encounter any problems. You may also be interested in this: http://www.phpfour.com/blog/2008/07/extended-model-for-codeigniter/ Which was apparently inspired by cakephp's Model implementation Model library - El Forum - 10-05-2009 [eluser]imn.codeartist[/eluser] nice, keep up the good work :-) Model library - El Forum - 10-05-2009 [eluser]davidbehler[/eluser] What happens if my primary key is not 'id' but 'table_id' or something similar? I think models should be more flexible and not be restricted to a specific set of naming conventions Model library - El Forum - 10-05-2009 [eluser]ray73864[/eluser] i have to agree with waldmeister on this one. Model library - El Forum - 10-05-2009 [eluser]imn.codeartist[/eluser] [quote author="waldmeister" date="1254746929"]What happens if my primary key is not 'id' but 'table_id' or something similar? I think models should be more flexible and not be restricted to a specific set of naming conventions [/quote] In that case, there you needs to write another wrapper class where you can run the query "desc tablename" and get the primary key and take the value as primary key Model library - El Forum - 10-05-2009 [eluser]davidbehler[/eluser] Wouldn't it be easier to adjust your model slightly? E.g. by adding another attribute: Code: class MY_Model extends Model { Model library - El Forum - 10-05-2009 [eluser]hugle[/eluser] [quote author="waldmeister" date="1254749400"]Wouldn't it be easier to adjust your model slightly? E.g. by adding another attribute: Code: class MY_Model extends Model { good point waldmeister ) your examples are everywhere I just wanted to ask, how do I pass the $table value to that model? If I do for example .... model: Code: class Book extends MY_Model { and the controller: Code: $this->load->model('book'); But as I said, I need to specify $table and por example $primary_key in model, so it updates/inserts/finds in different tables... how is that done? I think that should be done in Model... thanks ! Model library - El Forum - 10-05-2009 [eluser]davidbehler[/eluser] Following the example in the original blog post: Code: class Book extends MY_Model { Model library - El Forum - 10-05-2009 [eluser]ray73864[/eluser] have the runtime configs in the model itself, , then you should be able to do things like: Code: class Book extends MY_Model { Code: $this->load->model('book'); |