Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Court Ewing's Blog:
The Best Models are Easy Models
May 10, 2010 @ 20:51:57

In a recent post to his blog Court Ewing talks about what he sees as one of the most important parts of any framework-based application - good, easy models that are simple to use and well structured.

By treating your models as nothing more than a place to dump your data, you are doing yourself and your application a severe disservice; your business logic is going to be scattered throughout the rest of your application, and you will have a progressively more difficult time as you try to maintain and build upon your existing system. Do not fall into the anemic model trap.

He gives examples of good models (based on how Doctrine 2 handles them) to work with the data for a sample blogging application. His main "Article" model pulls from an abstract one to help define some relationships and magic methods to handle class properties in a protected and private way, depending on the context. He finishes the post with an example of how to use these new model classes to interact with his blog data.

tagged: model anemic tutorial easy doctrine

Link:


Trending Topics: