Welcome Guest, Not a member yet? Register   Sign In
Very unique / One time queries in model
#1

[eluser]Keyur Shah[/eluser]
Hello,

I'm trying to figure out how to organize my models in a way that the model code does not get cluttered by unique queries that get used only by a single controller. In the documentation and tutorials, i usually see CRUD type queries that are very generic and can be used my many controllers.

For example, here is one function in my orders model (along side the generic getAll, getSingle type queries)

Code:
function update_email_sent($ordernumber)
    {    
        if (isset($ordernumber)) {
            $data = array('EmailSent'=>1);
            $this->db->where("OrderNumber = $ordernumber");
            $this->db->update('Orders',$data);
        }
    }

Is there any other way of refactoring this function to keep the model page uncluttered by queries like this? Or should I create a new model page with the same name as the controller? Looking for some best practices.

Thanks!
#2

[eluser]Burak Guzel[/eluser]
I don't see anything wrong with that. It is good to keep your Controllers lean, but Models do not have to be. There is nothing wrong with having a Model method that gets called only by a single Controller.

But if you are repeating the basic CRUD methods across all of your Models (such as getAll and getSingle), you might want to create a base Model class (such as MY_Model), which you can extend with your Models.
#3

[eluser]Keyur Shah[/eluser]
Thanks for the response. It feels cluttered and disorganized, but it seems like the best way to go. Easier than managing separate files for each controller.




Theme © iAndrew 2016 - Forum software by © MyBB