php - Symfony FOSUserBundle - include login form in layout template -


we've configured fosuserbundle; login, register, reset password, etc, working fine.

now want incorporate login form our general site layout, notably placing form top-right section of layout header. doing easy enough if dealing username , password fields. can't seem figure out how obtain csrf token generated fosuserbundle service:

$this->container->get('form.csrf_provider')->generatecsrftoken('authenticate'); 

i tried calling above within twig extension otherwise works fine apparently extension can't reference container.

surely there easy way obtain fosuserbundle csrf token globally?

thanks! jason

you can define function in 1 of controllers

public function gettokenaction() {     return new response($this->container->get('form.csrf_provider')                             ->generatecsrftoken('authenticate')); } 

and embed form via

<input type="hidden" name="_csrf_token" value="{% render('yourbundle:yourcontroller:gettoken') %}" /> 

you need include following @ top of controller:

use symfony\component\httpfoundation\response; 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -