问题
In symfony, I see some coders put business logic in the actions ( controllers that is ), and some coders put it in the models ( Doctrine ). Where should the business logic belong, in the controller or model? What if I didn't use Doctrine, and it was just plain text files?
回答1:
Put the business logic in the controller is a bad pratice, the model is home for it.
If you don't have Doctrine, you can still have entities, model classes of your own (you should). Your files can be abstracted, and then put their business logic in their own classes, not in the controller.
It's all about MVC, and the M is really up to you.
回答2:
Standard Symfony and MVC conventions would have the controller only doing what is necessary to receive information passed from the view or to the view. Any data processing of that information, for the most part, should sit inside your model and library classes where they could be set up for optimal reuse or structured code organization.
One of the greatest strengths of Symfony is the fact that any other good Symfony developer can quickly code into a project of any other good Symfony developer, mostly because of the MVC conventions and the organization that Symfony forces upon your development with good coding standards.
回答3:
Bus. logic should not live in controllers. Controllers should well, control or direct the flow of control in the application they live in.
Bus. logic should live in domain level objects where they could be shared amoung various applications.
来源:https://stackoverflow.com/questions/8851629/symfony-business-logic