CodeIgniter Forums

Full Version: Models - How do YOU construct them?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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

$itemInfo = array( 'active' => 0 );
// update item
if ($this->Item_model->update_item($item_id, $itemInfo)) {
} else {

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!

El Forum

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.