Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override FOSUserBundle routes Symfony2

I would like to override some routes from FOSUserBundle

MyBundle/Resources/config/routing/security.yml

fos_user_security_login:
    path:     /{_locale}/login
    defaults: { _controller: FOSUserBundle:Security:login }
    requirements:
        _locale: %locales%

fos_user_security_check:
    path:     /login_check
    defaults: { _controller: FOSUserBundle:Security:check }
    requirements:
        _locale: %locales%

fos_user_security_logout:
    path:     /{_locale}/logout
    defaults: { _controller: FOSUserBundle:Security:logout }
    requirements:
        _locale: %locales%

But it does not works, route are not found

MyBundle/Resources/config/routing/security.xml

<?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">

    <route id="fos_user_security_login" pattern="/{_locale}/login">
        <default key="_controller">FOSUserBundle:Security:login</default>
    </route>

    <route id="fos_user_security_check" pattern="/login_check">
        <default key="_controller">FOSUserBundle:Security:check</default>
        <requirement key="_method">POST</requirement>
    </route>

    <route id="fos_user_security_logout" pattern="/{_locale}/logout">
        <default key="_controller">FOSUserBundle:Security:logout</default>
    </route>

</routes>

This works but I don't know how to pass my locales parameter from parameter.yml

like image 752
Ajouve Avatar asked Feb 12 '23 04:02

Ajouve


1 Answers

First of all the the yaml routes are not working because the FOSUserBundle Routes are defined in xml. So your yaml routes won't imported.

here the FOSUserBundle Routes: https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/config/routing

If the FOSUserBundle is the parent bundle of your userbundle you are able to rewrite the FOSUserBundle routing resources. How to do this is explained here: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc

Further more to answer to the last point how to pass the locale into the route is described here: http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc

<route id="contact" path="/{_locale}/contact">
    <default key="_controller">AcmeDemoBundle:Contact:index</default>
    <requirement key="_locale">%locales%</requirement>
</route>
like image 164
Nextar Avatar answered Feb 19 '23 05:02

Nextar