Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfoyn 3.4 : FOS User Bundle : Override Controller #2791

Closed
garalimedkarim opened this issue Apr 30, 2018 · 1 comment · Fixed by #2807
Closed

Symfoyn 3.4 : FOS User Bundle : Override Controller #2791

garalimedkarim opened this issue Apr 30, 2018 · 1 comment · Fixed by #2807

Comments

@garalimedkarim
Copy link

garalimedkarim commented Apr 30, 2018

Symfony version:

            "name": "symfony/symfony",
            "version": "v3.4.8",

Symfony FOSUserBundle versions:

            "name": "friendsofsymfony/user-bundle",
            "version": "v2.1.2",

Description of the problem including expected versus actual behavior:
I'm trying to override loginAction, but it doesn't work, I think the documents are not very detailed So it must provide at least one exemple for override Controller, Template,etc ...

Steps to reproduce:

  1. I know that the inheritance was deprecated but I have created a bundle in which I will override FOS User Bundle functionnalities, I called this Bundle src/MyVendor/MyVendorFOSUserBundle.
    test autoload => OK.

2.I copied SecurityController.php from the vendor/ in my bundle MyVendorFOSUserBundle/Controller/ And I add the @route Decorator above the loginAction but I get an issue when submiting login form => Invalid CSRF token: by debuggin I fount that the $tokenManager doesn't be injected in the Controller so it's take null value: In this code I just added the @route decorator and extends BaseController to the Contoller copied.

The result Controller:

#src/MyVendor/MyVendorFOSUserBundle/Controller/SecurityController.php:

    class SecurityController extends BaseController
    {
    private $tokenManager;

    public function __construct(CsrfTokenManagerInterface $tokenManager = null)
    {
        $this->tokenManager = $tokenManager;
    }
     /**
      * @param Request $request
      * @return Response
      * @Route("/login")
      */
    public function loginAction(Request $request)
    { ... }

  1. tried to add the attribute name in @route Decorator and I kept the same route name as it is in FOS User Bundle but in this case the Controller of FOS User bundle which is executed and my new Controller was ignored ( I test this by putting die('test') on Controller contructor)

The Question What is the solution to correctly override this action ?

@garalimedkarim garalimedkarim changed the title Symfoyn 3.4 : FOS User Bundle : Override Controller Ask Symfoyn 3.4 : FOS User Bundle : Override Controller Apr 30, 2018
@DeveloperSlope3
Copy link

DeveloperSlope3 commented May 3, 2018

I had the same problem. Take a look here: #2778

In Sf3.4 they have change the way to do some tings. Overriding controllers is deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants