简体   繁体   中英

Overriding the FOS UserBundle in Symfony2 (also using Fr3d ldap bundle)

Because I would like to override the templates of the FOS UserBundle in Symfony2, I am trying to adapt my custom UserBundle.

I made templates (and followed the exact same structure as the FOS bundle) and I've made an "empty" extension for every controller.

However, as soon as I make the override active, clear the cache and attempt to login, there is an error and I don't understand why. The error reads:

An exception has been thrown during the rendering of a template ("Route "login" does not exist.") in "FOSUserBundle:Security:login.html.twig".

This is my own SecurityController for example:

<?php

namespace R\Bundle\UserBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\SecurityController as BaseController;

class SecurityController extends BaseController
{ }

By activating the override (before clearing the cache), I mean uncommenting this line:

<?php

namespace R\Bundle\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class RUserBundle extends Bundle
{
 public function getParent()
 {
    return 'FOSUserBundle'; <-- this line activates or deactivates the override
 }
}

The login.html.twig template in my own UserBundle, which is supposed to override the one in the FOS UserBundle, is still an exact copy of the original one (which functions fine if the override is not active).

I assume I somehow need to override the routing files as well, but if I copy them into my custom UserBundle the error remains.

The login route is not included. You need to include it, see step 6 :

# app/config/routing.yml
fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

The error was actually something completely different:

A twig snippet was called for by mistake (in a complex hierarchy of templates) and it still contained an old path name. As this path was called login, I was convinced the error had something to do with my newly activated UserBundle. So Symfony2 pointed me to a totally wrong location; the error was not to be found anywhere close to there ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM