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
I leave this for future reference, in addition to @jfcartier's answer:
In case you need a custom
logout
path instead offos_user_security_logout
:... then you also need to define it in
routing.yml
:Though, make sure that it's defined before
fos_user
- otherwise you'll get the same error: You must activate the logout in your security firewall configuration.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: