Mvc + Service Layer

Note: I’ve read another thread on the same subject , only would like more opinions .

I’m using Yii Framework , but in some projects involving complex processes in some cases I did these processes in "Model " , in other cases I did the " Controller " (which I admit is a big mistake because the code gets stuck one controller ) .

In the case of model I made processes such as :

  • To save pending , registering all charges , send an email to the customer , etc. ( I did not do all this but I was thinking of doing )

Okay when you made ​​that code , you know that it will register the collection together and it is not necessary to register the charge , but when else will change your code it can expect the médodo " Save Pending " just save the pendency and not all charges .

This weekend , I thought about the possibility of joining the MVC (which I really like ) with a service layer that is very necessary to me , is that it may cause some impact to the goals of " MVC " ?

Wow, this is interesting topic to discuss.

First of all, personally I prefer not to overload models with such logic as sending email, because it’s not related to storing data.

There’s a pretty good replacement for that: events. So the controller processes the request and returns the response, models deal with storage (db, file, whatever), and event handlers observe all the fun and shoot when needed.

Speaking about service layer, there is one in Laravel and they can live with that.

Btw, how do you plan to create this layer?

I plan to create a "protected / services" folder and then create classes, eg PendingService, the parameters for the service methods can be the models themselves (active record)