12

Fat models and how they change how you use the Model class

http://cakebaker.42dh.com

At the beginning of my time with CakePHP I used to write “skinny” models, i.e. they only contained association definitions and some validation rules, and nothing else. Everything was done in the controller using the methods provided by the Model class.

In the meantime I follow the “skinny controller, fat model” principle, and so a lot of the logic I previously did in the controller is now done in the model. A side effect of this is that I tend to no longer use certain methods like Model::findAll() in my controllers. For example, if I had to write some functionality to retrieve the 10 most recent posts I would have written it in the past like:

Read »
mark's picture
Created by mark Created 47 weeks 6 days ago – Made popular 47 weeks 5 days ago
Category: Programming   Tags: