Routing configuration Symfony 3.4
1 min readSep 26, 2018
Un nouvel attribut a été ajouté cette semaine pour faciliter la configuration du routing, on parle de l’attribut ‘controller’, dont voici des exemples d’implémentation :
- YML configuration:
# new SF >= 3.4 routing configuration
homepage:
path: /index
controller: AppBundle:HomeController:home# \InvalidArgumentException The routing file must not specify
# both the "controller" key and the defaults key "_controller"
# for "homepage"
homepage:
path: /index
controller: AppBundle:Homepage:show
defaults:
_controller: AppBundle:Blog:index
- XML configuration:
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"><!-- new SF >= 3.4 routing configuration --><route id="app_homepage" path="/" controller="AppBundle:Homepage:show" /> <!--
\InvalidArgumentException The routing file must not specify both
the "controller" key and the defaults key "_controller" for "homepage"
--><route id="app_blog" path="/blog" controller="AppBundle:Homepage:show"><default key="_controller">AppBundle:Blog:index</default></route>
</routes>
Comme vous avez pu voir une seule option est permise, profitez en !