Generic Data Retrieval Model? - 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: Generic Data Retrieval Model? (/showthread.php?tid=55557) |
Generic Data Retrieval Model? - El Forum - 11-01-2012 [eluser]Unknown[/eluser] Hi Folks, I am very new to CodeIgniter and I had a question about best practices. I had an idea that it would perhaps be useful to have one generic model to parse data. I thought that it might be useful to create one generic model to reuse it again and again, but I am not sure if this is a violation of "MVC" principles or not. Here's the code in my controller: Code: $data['holidays'] = $this->fetch_data->arFetch('cal','full_date',array('holiday'), array('holiday.cal_id = cal.id'),''); Here's the code in my model: Code: function arFetch($table, $cols, $join, $joinOn, $where) { While I first thought this was a terrific idea, now I am not so sure. I almost feel as though I am using the model as a function, which does not seem to be the appropriate purpose. Your thoughts would be greatly appreciated. Thanks for the help everyone! Kind Regards, Tom G Generic Data Retrieval Model? - El Forum - 11-01-2012 [eluser]alexwenzel[/eluser] You can checkout my CRUD model (below in my signature). Maybe it fits better your needs. Generic Data Retrieval Model? - El Forum - 11-01-2012 [eluser]solid9[/eluser] Don't reinvent the wheel. study MY_Model. Generic Data Retrieval Model? - El Forum - 11-01-2012 [eluser]Unknown[/eluser] [quote author="solid9" date="1351767180"]Don't reinvent the wheel. study MY_Model. [/quote] This is what I was seeking. While I understand that it is not difficult to write SQL, I'd like something to make it easier to use active records and the like. I like the database agnosticism and the auto escaping, but having many lines of code in the model each time I want to build a query the "AR" way seems unnecessary. Have a great day and thanks again for the response! |