![]() |
Developing models quickly? Any tips... - 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: Developing models quickly? Any tips... (/showthread.php?tid=12484) |
Developing models quickly? Any tips... - El Forum - 10-21-2008 [eluser]Daniel H[/eluser] My new projects data model design comprises 66 db tables. Developing models for each table is terrifying me! The thing is every model is practically the same - class variables the same as the field names, and reset(), save(), delete() methods. Does anyone have a neat method for auto-generating their models or should I just get on with it and stop complaining?! Developing models quickly? Any tips... - El Forum - 10-21-2008 [eluser]Sam Dark[/eluser] Try Doctrine. http://www.doctrine-project.org/ Developing models quickly? Any tips... - El Forum - 10-21-2008 [eluser]Bramme[/eluser] You could write a general model for all the identical tables that, in addition to the queries or whatever, receives a table name. Thus you won't need 66 models. Developing models quickly? Any tips... - El Forum - 10-21-2008 [eluser]Daniel H[/eluser] I like the idea of Doctrine but it'll probably take me a while to get my head around it. I guess I should just create a generic model for 'relationship' tables which by and large only have two fields. Thanks. Developing models quickly? Any tips... - El Forum - 10-21-2008 [eluser]Stefano G[/eluser] Daniel, in a recent blog entry, Michael Wales posted an article about an Extended Model that has the all the basic methods you need (select all, get by id and so on): http://michaelwales.com/asides/phpfours-extended-codeigniter-model/ Of course this is just a start but you don't need to reinvent the wheel and you can use it either as a super model or as a base for implementing your own functionalities. Anyway in my project I use a model for operating on different tables (passing the tabname as an argument) if the operations are the same (and the structures as well). For example, if I need some tables for combobox I will name the id field 'id' and the desc 'desc' so I can use only one method/query for generating combobox from different tables. cheers! Stefano Developing models quickly? Any tips... - El Forum - 10-22-2008 [eluser]Daniel H[/eluser] Thanks for that link. I went about rolling my own for key tables by extending the model class to give a get(), save(), delete() and count() function for any model that extends it. Here it is attached... MY_Model, then a model template, and then a DB helper. Let me know if you have any suggestions for making it better... Developing models quickly? Any tips... - El Forum - 10-22-2008 [eluser]Stefano G[/eluser] to me it looks ok, I think that the better approach is to have a Super-Model and then extending and implementing just small pieces... keep us informed! Cheers! Stefano |