Developer 3
Developer 3

Reputation: 11

fosuserbundle overriding controller in Symfony3.4

At first we had Sf3.0 + FOSUserBundle2 (we followed the online documentation and all was OK) and along the project we have upgrade to SF3.4, but now we realize we need to override the controllers and the problem is that our code is eing ignored

Our code is based on the official documentation of 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;
    }
}

Thanks a lot!

Upvotes: 0

Views: 537

Answers (2)

Developer 3
Developer 3

Reputation: 11

The problem is solved.

They have changed the way to do, but no the documentation:

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

Upvotes: 0

hbgamra
hbgamra

Reputation: 879

within UserBundle.php do you put the folowing function ?

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

Upvotes: 1

Related Questions