Dependency injection : Get Param in controller

I am in the process of migrating an application from Symfony 2.8 to Symfony 3.4

The services are now private and therefore instead of making a direct call to the services from the container, we must use dependency injection as a workaround.

For parameters, how can we get them in controller and of course we must always respecting the good practices.

This the following script and this the environment as an example :

class CmsController extends Controller
{
    /**
     * @param Request $request
     *
     * @return Response
     */
    public function importExportAction(Request $request): Response
    {
        $adminPool = $this->get('sonata.admin.pool');
        $env = $this->getParameter('environment');

         return new Response('OK');
    }
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *