RS7
RS7

Reputation: 2361

MVC - Codeigniter

Where should intermediate code be placed? (something that ins't just storing/retrieving data from DB nor processing requests/views)

For example,

Say I have Listings and I create CRUD functions in the model. These Listings may require more complex tasks such as pausing and resuming, which may require some time calculations, error setting, etc. Should these be placed in the model or should I wrap a simple model in a library and use that as a middleman for the model?

At the moment I'm thinking of using Drivers/Libraries and keeping models rather simple, except for some dynamic SELECT filters. I'm getting a bit confused though, since I'm guessing I'd probably have to recheck variables, dependencies, etc in the model after doing it in the library, yes?

I'd most likely either squish everything together in the model and check once or separate and check twice?

Upvotes: 0

Views: 95

Answers (1)

Skittles
Skittles

Reputation: 2918

The general rule of thumb is:

1) Perform all business logic in the models.

2) Perform actions like a traffic cop would in controllers. (directing users to new views based on results of activities.)

3) Perform only presentational logic in views.

Anything else that you would like to do that would be considered, "intermediary", could reside in a Library or Helper.

It should be noted though that if you write a Library, don't forget to get an instance of the current CI object in your class so that you have it to use with your internal class methods.

class Your_lib {
  $CI =& get_instance();
  ...
}

Hope that helps.

Upvotes: 3

Related Questions