Where to place business logic is Symfony 2 model layer? Where to place business logic is Symfony 2 model layer? symfony symfony

Where to place business logic is Symfony 2 model layer?


Create an ArticleManager class in your service layer, and handle any business logic there. You can pass the router to it through dependency injection.

For your example, ArticleManager would have a getUrl(Article $article) method which would use the router instance (that you either injected through __construct or a separate setter method) to generate the Url based on properties of $article, and return it.

This method will ensure that your business logic doesn't pollute the view or controller layers.

Be sure to read up on the Service Container docs.