Q
Q
Quber2014-05-27 11:02:25
symfony
Quber, 2014-05-27 11:02:25

How to make a route (routing) parameter optional in Symfony 2?

Let's say we have a route like this:

feedback:
    pattern:  /{_locale)/feedback
    defaults: { _controller: AcmeHelloBundle:Feedback:index }
    requirements:
        _locale: en|ru

How to make _locale optional?
For the following paths to work on the same route
sait.ru/feedback
sait.ru/en/feedback
sait.ru/ru/feedback
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Solovyov, 2014-05-27
@Quber

the locale must be used as a prefix

you_route:
  resource: "@CustomBundle/Resources/config/routing.yml"
  prefix:   /{_locale}
  requirements:
    _locale: en|ru
  defaults: { _locale: en}

or use jmsyst.com/bundles/JMSI18nRoutingBundle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question