起初我们有Sf3.0 + FOSUserBundle2(我们遵循在线文档,一切都还可以),在项目中我们已升级到SF3.4,但现在我们意识到我们需要覆盖控制器,问题在于我们的代码被忽略了
我们的代码基于FOSUsserBundle的官方文档
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;
}
}
非常感谢!
答案 0 :(得分:1)
public function getParent()
{
return 'FOSUserBundle';
}
答案 1 :(得分:0)
问题解决了。
他们改变了做法,但没有改变文件:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2778#issuecomment-382700365