1
votes

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 !

1

1 Answers

0
votes

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' %}