Symfony 3.4 中的 fosuserbundle 覆盖控制器

fosuserbundle overriding controller in Symfony3.4

起初我们有 Sf3.0 + FOSUserBundle2(我们按照在线文档进行操作,一切正常)并且随着项目升级到 SF3.4,但现在我们意识到我们需要覆盖控制器和问题是我们的代码被忽略了

我们的代码基于FOSU​​sserBundle的官方文档

namespace UserBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security;
use FOS\UserBundle\Controller\SecurityController as BaseController;

class SecurityController extends BaseController {

    private function renderLogin(array $data) {
        //Redirigimos a donde corresponda, si ya estamos logados
        $security = $this->container->get('security.authorization_checker');
        if (!$security->isGranted('IS_AUTHENTICATED_ANONYMOUSLY')) {
            $url = 'admin';

            return new RedirectResponse($this->container->get('router')->generate($url));
        }

    $response = new Response();

    $response->setContent($this->container->get('twig')->render('FOSUserBundle:Security:login.html.twig', $data));

        return $response;
    }
}

非常感谢!

在 UserBundle.php 中,您是否输入了以下分数?

public function getParent()
{
    return 'FOSUserBundle';
}

问题已解决

他们改变了做事的方式,但没有文档:

https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2778#issuecomment-382700365