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

Symfony Finland:
Why have Controllers as Services in Symfony?
Feb 29, 2016 @ 15:13:05

On the Symfony Finland blog there's a post that talks about Symfony controllers and services and how making the controllers services instead could be beneficial.

Controllers are quite straightforward in their actions (ha-ha) and simply take requests and return responses. The concept of a services is simple too, it's technically just a PHP object that performs a task over and over again somewhere in your application.

[...] Using services for tasks repeating in multiple locations of your application undoubtedly makes sense, but why should you shrinkwrap your controllers into a service? If you look at the official Symfony Demo Application does not do this. So why should yours?

Once again he uses the eZ Platform software to illustrate the point, describing how it packages up the controllers into services, including the configuration required to make it work. He shows how the dependency injection works and how controllers/services can call actions in other controllers/services easily.

tagged: controller service symfony ezplatform tutorial configuration yaml

Link: https://www.symfony.fi/entry/why-have-controllers-as-services-in-symfony


Trending Topics: