FOSUserBundle logout with prefix doesn't work
fosuserbundle, localization, symfony
Solution
In your configuration file, you need to use routes instead of URLs. If it starts with a "/" it will be treated as an URL, else it will be treated as a route. If you use routes instead of URLs, the locale will be taken care of automatically. For example, here is my security.yml configuration:
security:
public:
pattern: ^/
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
provider: fos_userbundle
csrf_provider: form.csrf_provider
default_target_path: index
anonymous: true
logout:
path: fos_user_security_logout
target: index
Problem
I am having a very strange problem with symfony2 and the FOSUserBundle. I can logout with /en/logout, but not with /nl/logout or /fr/logout. When I try to logout with nl or fr I get: ``` You must activate the logout in your security firewall configuration. ``` Although I configured it. I can't seem to wrap my head why the /en/logout works and the rest doesn't. This is my code: security.yml ``` security: providers: fos_userbundle: id: fos_user.user_provider.username_email encoders: FOS\UserBundle\Model\UserInterface: sha512 firewalls: main: pattern: ^/ form_login: provider: fos_userbundle csrf_provider: form.csrf_provider check_path: fos_user_security_check default_target_path: /%locale%/login always_use_default_target_path: true failure_path: /%locale%/login logout: path: /%locale%/logout target: homepage anonymous: true ``` routing.yml ``` user bundle > FOS fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml" prefix: /{_locale} requirements: _locale: fr|nl|en ``` controller ``` class LoginController extends Controller { /** * @Route("{_locale}/logout-test", name="logout", defaults={"_locale"="en"} , requirements = {"_locale" = "fr|en|nl"}) * @Template() */ public function logoutAction() { $test = ""; #throw new \RuntimeException('You must activate the logout in your security firewall configuration.'); #return $this->redirect($this->generateUrl('homepage'));; } } ``` Can anyone help me out, or tell me where to look next? It would be much appreciated