Question

CakePHP doesn't seem to ever mention separating the business logic and data access layers of an app. This is my first MVC app and my "fat models" are turning out to be very fat because they contain all kinds of business logic whose only real thing in common is requiring access to the same database.

When you hear the suggestion to move your business logic from controllers into the model, is it really acceptable to wind up in such a state? Does CakePHP provide any structure for a separate business logic layer as part of their framework?

Thanks, Brian

Was it helpful?

Solution

No. It sounds to me that what you are running into is the classic downside of the Active Record pattern. Also, it doesn't help that CakePHP is all based around result associative arrays instead of object instances. I suggest that you take a look at packages like Doctrine 2. It implements a DataMapper pattern instead of an ActiveRecord pattern. It keeps your business logic completely separate from your data access layer.

There are CakePHP extensions to integrate Doctrine into CakePHP.

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