0
votes

I am trying to redeclare FOSUserBundle ProfileController, but when I am doing it nothing changes. I have followed the instruction https://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html and created: /src/UserBundle/UserBundle.php

    <?php

namespace UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class UserBundle extends Bundle
{
  public function getParent()
  {
    return 'FOSUserBundle';
  }
}

and /src/UserBundle/Controller/ProfileController.php

<?php
namespace UserBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Controller\ProfileController as BaseController;


class ProfileController extends BaseController
{
  public function editAction(Request $request)
  {
    var_dump("I am HERE");exit();

    return $request;
  }
}

What am I doing wrong could somebody give an advise?

1
note that "Bundle inheritance is deprecated since Symfony 3.4" and also check this stackoverflow.com/questions/49917021/… - Pavel Alazankin

1 Answers

0
votes

In Symfony 3 you don't use bundle inheritance anymore as @Pavel Alazankin already pointed out. To override FOSUser controllers you need to:

  1. remove the function getParent() inside your USerBundle
  2. find out which routes are used by FOSUserBundle here and override them in your controller
<?php namespace UserBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use FOS\UserBundle\Controller\ProfileController as BaseController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\Model\UserManagerInterface;

class ProfileController extends BaseController {

 public function __construct(EventDispatcherInterface $eventDispatcher,
     FactoryInterface $formFactory, UserManagerInterface $userManager)
 {
     parent::__construct($eventDispatcher, $formFactory, $userManager);
 }

/**
 * override FOSUserBundle
 * @param Request $request
 *
 * @Route(
 *      "/login",
 *      name="fos_user_profile_edit"
 *  )
 * @Method("GET|POST")
 *
 * @return Response
 */
 public function editAction(Request $request)
 {
    var_dump("I am HERE");exit();

    return $request;
}