1

I have a question about including login form of FOSUserBundle in other layout. In some way, I want to have two login form :

  • One login form, without extends, that I can include everywhere, for example here in my homepage
  • One login form who extends my basic layout, display for example when you call /login

I try something but I have this error :

An exception has been thrown during the rendering of a template ("No route found for "GET Security:LoginBisAction"") in rSWelcomeBundle:Homepage:index.html.twig at line 15.

I have two bundles : one WelcomeBundle and one UserBundle which extends FOSUserBundle.

In rs/WelcomeBundle I have my homepage, and I include the login form in the right block :

{% extends "rsWelcomeBundle::layout.html.twig" %}

{% block title "Page d'accueil" %}

{%  block body %}
    <div class="span6">
        <div class="well">
            <h2>Présentation du site</h2>
            <p>Rejoignez nous, parce que ceci cela...etc ! </p>
            <p><a href="{{ path('fos_user_registration_register') }}" class="btn ">Je m'inscris !</a></p>
        </div>
    </div>
    <div class="span6">
        <div class="well">
            {% render 'FOSUserBundle:Security:LoginBisAction' %}
        </div>
    </div>

{% endblock %}

In rs/UserBundle, at root, in rsUserBundle.php I extends FOSUserBundle :

<?php

namespace rs\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class rsUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

In rs/UserBundle/Ressources/views/layout.html.twig :

{% extends "rsWelcomeBundle::layout.html.twig" %}

{% block body %}
  <div class="span4 offset4">
    <div class="well">
      {% for key, message in app.session.flashbag.all() %}
          <div class="alert alert-{{ key }}">
              {{ message|trans({}, 'FOSUserBundle') }}
          </div>
      {% endfor %}

      {% block fos_user_content %}
      {% endblock fos_user_content %}
    </div>
  </div>
{% endblock %}

In rs/UserBundle/Ressources/views/Security/login.html.twig :

{% extends "FOSUserBundle::layout.html.twig" %}

{% block fos_user_content %}
{% if error %}
    <div>{{ error|trans({}, 'FOSUserBundle') }}</div>
{% endif %}

{% include "UserBundle:Security:login_content.html.twig" %}

{% endblock fos_user_content %}

In rs/UserBundle/Ressources/views/Security/login_content.html.twig :

<form action="{{ path("fos_user_security_check") }}" method="post">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

    <label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" />

    <label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
    <input type="password" id="password" name="_password" />

    <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
    <label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label>

    <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
</form>

And in rs/UserBundle/Controller/ I have only one file UserController.php :

<?php

namespace rs\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use FOS\UserBundle\Controller\SecurityController as SecurityController;

use rs\UserBundle\Entity\User;

/**
 * Description of UserController
 *
 */
class UserController extends SecurityController {

    public function LoginBisAction()
    {
        $csrfToken = $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate');

        return $this->container->get('templating')->renderResponse('FOSUserBundle:Security:login_content.html.twig', array(
            'last_username' => null,
            'error'         => null,
            'csrf_token'    => $csrfToken
        ));
    }
}

What's wrong, did I have to create a route somewhere ? Why my loginAction is not found when I go to my homepage ? Why I have this error :

An exception has been thrown during the rendering of a template ("No route found for "GET Security:LoginBisAction"") in rSWelcomeBundle:Homepage:index.html.twig at line 15.

Thanks a lot !

user2178964
  • 124
  • 6
  • 16
  • 40

1 Answers1

0

As in error message: "No route found for "GET Security:LoginBisAction"". So you are call not existed route (exactly not existed controller action). Please notice that there are no LoginBisAction for raw Security FOSUser bundle. Try to call your extended controller action:

{% render 'rsUserBundle:User:LoginBisAction' %}
NHG
  • 5,807
  • 6
  • 34
  • 45
  • Thanks for your awnser, but it's not working, I try what you said and I have always : "An exception has been thrown during the rendering of a template ("No route found for "GET User:LoginBisAction"") in rsWelcomeBundle:Homepage:index.html.twig at line 15." Also, if I try {% render 'FOSUserBundle:Security:Login' %} Or : {% render 'FOSUserBundle:Security:LoginAction' %} It's not working either... – user2178964 Apr 05 '13 at 05:57
  • did you import this to app/config/routing.yml `fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml"` It seems to be the routing problem – tigris Apr 05 '13 at 14:34
  • Yes I do it ;) Somebody said to me to use that in my rs/WelcomeBundle in my homepage layout : `{% render(controller('robStormUserBundle:User:loginBis')) %}` I don't really understand why, I think if I don't want to write "render(controller..." I need to define some route in my routing.yml... Anyway, now I have this error : An exception has been thrown during the rendering of a template ("Unable to find template "FOSUserBundle:Security:login_content.html.twig".") in rsWelcomeBundle:Homepage:index.html.twig at line 15. – user2178964 Apr 05 '13 at 15:29
  • See a partial answer here : http://stackoverflow.com/questions/15855515/fosuserbundle-no-route-found-for-securitylogin – user2178964 Apr 07 '13 at 09:08