Question

I am currently developing a web project using Yii framework. I'm wondering where is a good place to put all the business logic, in the Controllers, or Models(models here as in mappings from database tables to actual objects)? Both doesn't seem right. I think I might need an extra "asset" layer in between controller and models, but I have no idea how to start. Any suggestions?

Was it helpful?

Solution

Generally the suggestion is to go about using Fat Models and Thin Controllers. So business logic in your model. It makes it far easier to make your code re-useable.

More info here: http://www.yiiframework.com/doc/guide/1.1/en/basics.best-practices

If you've got a lot of custom logic, you could potentially have an "asset" layer of additional models that handled your DB models. Depends on your specific system though … I'm finding I do use CFormModel objects this way at times to map from a form with a bunch of different models to the models as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top