Model library |
[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/mode...hp-if.html Please check and test it regards
[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/exte...deigniter/ Which was apparently inspired by cakephp's Model implementation
[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
[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
[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 {
[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 !
[eluser]davidbehler[/eluser]
Following the example in the original blog post: Code: class Book extends MY_Model {
[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'); |
Welcome Guest, Not a member yet? Register Sign In |