Symfony2 Overriding Controllers

I am using FOSUserBundle and I want to override its registerAction controller. I have read the documentation related to FOSUserBundle overriding controllers, but it doesn't work. By repeating the little message in the controller, it is not printed in the template.

This is how I chose:

I inherit my bundle from FOSUserBundle:

namespace Jheberg\MembersBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

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

      

And I override registerAction on a file named RegistrationController.php

in my package controller directory:

namespace Jheberg\MembersBundle\Controller;

use FOS\UserBundle\Controller\RegistrationController as BaseController;

class RegistrationController extends BaseController
{
    public function registerAction()
    {
        echo 'foo';
        $response = parent::registerAction();

        // do custom stuff

        return $response;
    }
}

      

Do you have a solution?

+3


source to share


2 answers


Just spent hours trying to get this to work and finally figured it out. The part I was missing was extending my User class with the User object from MyUserBundle. For example:

namespace MyNamespace\MyMainBundle\Entity;

use MyNamespace\MyUserBundle\Entity\User as BaseUser;

class User extends BaseUser
{
}

      

The custom object is identical to the one in the FOSUserBundle (only with a different namespace).



namespace MyNamespace\MyUserBundle\Entity;

use FOS\UserBundle\Model\User as AbstractUser;

abstract class User extends AbstractUser
{
}

      

If I hadn't, as Jeffrey pointed out, MyUserBundle would not have been used at all (as if it wasn't there). Now all my overridden views, controllers, etc. Are used. Hope this helps.

+3


source


It doesn't work for me. I am trying to make your decision. Finally, I just cleared the cache by running the php bin / console cache: of course I figured it out inside my project. And func is like a charm.

So, try clearing your cache.



And sorry for my bad english.

0


source







All Articles