Controller which renders a template and returns a response (HttpFoundation)
- Test more than one Symfony version!
- Uses Engine as controller argument for easier configuration with Symfony 3.3
- Because Twig was not found in autoconfig as a constructor argument
- http://symfony.com/doc/current/controller.html#fetching-services-as-controller-arguments
- constructor tested only with default value
Composer configuration for use in Symfony Framework or elsewhere where this controller is called by the Symfony kernel
- as long as there is the tiniest risk that Symfony < 3.3 could be installed by composer
- ie Symfony 2.8 is supported until close to the end of 2018 it will survive up to mid 2019 and more in distributions like Debian
- https://symfony.com/roadmap
$ composer req symfony-util/controller-using-templating-http-foundation-http-kernel
otherwise just
$ composer req symfony-util/controller-using-templating-http-foundation
function configureRoutes(RouteCollectionBuilder $routes)
{
// ...
$routes->add('/', SymfonyUtil\Controller\EngineAsArgumentController::class, 'index');
// ...
}
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
// ...
$c->autowire(SymfonyUtil\Controller\EngineAsArgumentController::class)
->setAutoconfigured(true)
->addTag('controller.service_arguments')
->setPublic(false);
// ...
Icon: https://material.io/icons/#ic_wallpaper
- string arguments can officially be type-hinted from php 7.0
- http://php.net/manual/en/functions.arguments.php
- declare(strict_types=1);
- function f(): float
- function s(string $s)