Library, Controller, Model, Helper, or Plugin? - 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: Library, Controller, Model, Helper, or Plugin? (/showthread.php?tid=9340) |
Library, Controller, Model, Helper, or Plugin? - El Forum - 06-22-2008 [eluser]Dave Stewart[/eluser] Hi there, For my application, I've a large number of SQL select statements I want to store in an array, to be used across controllers / requests. Essentially they will deliver different table views, based on reports a user might request. So my question is: what would be the best construct to store them in? Should I create a library, helper, or should the requests be part of a model that is loaded in each time, or something else? Thanks for your help, Dave Library, Controller, Model, Helper, or Plugin? - El Forum - 06-22-2008 [eluser]libnac[/eluser] I think you must use models. you can use models in this way: yourmodelmodel.php class Yourmodel extends Model { function Yourmodel() {..} function view1() { $select_sql = "table1.*, .... "; return executeQry($select_sql); } function view2() { ... } ... function executeQry($select_sql) { $this->obj->db->select($select_qry); $query = $this->obj->db->get(); if($query->num_rows()>0 ) return $query->result(); } } } or something like this... And you can load this model in your controller constructor. class Yourcontroller extends Controller { function Yourcontroller() { $this->load->model("yourmodelmodel") } } I hope this will be useful for you Library, Controller, Model, Helper, or Plugin? - El Forum - 06-22-2008 [eluser]Dave Stewart[/eluser] Thanks Liberto. Actually, I'm not actually modelling data with this method, just storing SQL queries which will provide data that can be represented as a model. In the meantime, I just created a standard class that I loaded in as a library, and this seems to work fine. Mind you, the physical end result between using a model or a library would seem to be no different - you still call them the same way: $this->model_name->function() More opinions welcome! Thanks, Dave Library, Controller, Model, Helper, or Plugin? - El Forum - 06-22-2008 [eluser]Seppo[/eluser] Are you just storing the SQL string? You can use a config file for that. |