Welcome Guest, Not a member yet? Register   Sign In
Models - How do YOU construct them?
#1

[eluser]Jay Turley[/eluser]
So I've now been using CI on and off for several months. Not as often as I'd like, but more than I'd feared.

As as I have gotten better at using the framework, I wonder how other CI developers are developing their models.

For instance, my first models used the Data Object pattern, with full suites of getters and setters.

In later applications, my models have tended to be more careless, requiring the controllers to be aware of the database fields so I can do things like

Code:
$this->load->model('Item_model');
$itemInfo = array( 'active' => 0 );
// update item
if ($this->Item_model->update_item($item_id, $itemInfo)) {
    redirect($this->session->userdata('return_link'));
} else {
    $this->load->view('error');
}

This kind of approach also allows me to - for instance - just pop a recordset into an array in the model and toss it to the view for output processing.

It sure makes things easy, but it's more tightly coupled than my first approach.

So I'm curious. How are you all handling this? Do you vary your approach based on the application/site you are developing? Do you use a different approach?

Thanks for any responses!
#2

[eluser]Crimp[/eluser]
I never set anything model-related in the controller. I think it boils down to not confusing myself with changing shortcuts that seem genius at the time and result in a slap on the forehead when the code is reviewed months later. So the $itemInfo item is missing info.




Theme © iAndrew 2016 - Forum software by © MyBB