Routing configuration Symfony 3.4

FLEX Consulting
Sep 26, 2018 · 1 min read

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 !

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store