Overriding FOSUserBundle Controller

Discuss Symfony 2 bundles here

Moderators: dcobalt, tiagojsag

Overriding FOSUserBundle Controller

Postby flymke » Wed Jan 04, 2012 2:34 am

I want to override the RegistrationController.php of the FOSUserBundle.
I need to implement a log-data that I want to persist to my DB while a user registers at my site.

This is what I tried with following steps:
http://symfony.com/doc/2.0/cookbook/bundles/inheritance.html

1.) I registered the FOSUserBundle as the "parent" of my Bundle

Code: Select all
<?php
// src/My/MyBundle/MyMyBundle.php

namespace My\MyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

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


2.) I set up a file with the same name located at my bundle's controller folder:

Code: Select all
<?php
// src/My/MyBundle/Controller/RegistrationController.php

namespace My\MyBundle\Controller;

use FOS\UserBundle\Controller\RegistrationController as BaseController;

use My\MyBundle\Entity\Log;

class RegistrationController extends BaseController
{
    public function registerAction()
    {
        $response = parent::registerAction();
       
        // do custom stuff
       
        $log  = new Log();
        $log->setData('testdata');
        $em = $this->getDoctrine()
                  ->getEntityManager();
        $em->persist($log);
        $em->flush();

        return $response;
    }
}


However, it seems like "my" (above) RegistrationController.php in my bundle doesn't get loaded at all (an echo doesn't show anything either).

How can I override the RegistrationController?

And also: I have some other ressources (template files) of the FOSUserBundle that I am currently overriding in the main app/ressources folder. Is that the best practice? Or is there a way to override them in my bundle folder as well (e.g. /src/My/MyBundle/ressources)?

Many thanks,

Mike
flymke
Junior Member
 
Posts: 23
Joined: Wed Oct 05, 2011 12:15 pm

Re: Overriding FOSUserBundle Controller

Postby maastermedia » Sun Jan 08, 2012 11:43 am

I cannot tell for sure what is the problem with your overriding, however you can check docs for how to "properly" override controllers:
https://github.com/FriendsOfSymfony/FOS ... rollers.md

There is an example of how to override registration controller.

Regards, Peter.
User avatar
maastermedia
Senior Member
 
Posts: 199
Joined: Sat Aug 14, 2010 12:51 pm
Location: Slovenia

Re: Overriding FOSUserBundle Controller

Postby feifur » Wed Apr 11, 2012 10:34 pm

Hi flymke,
I have the same issue than you, i want to override the RegistrationController, but it seems that it not taking mi own controller,.
Did you solve the issue?
Thanks in advance!
rafa
feifur
Junior Member
 
Posts: 1
Joined: Wed Apr 11, 2012 10:31 pm

Re: Overriding FOSUserBundle Controller

Postby lalmohan » Fri Jul 27, 2012 9:17 am

Hi

I need to inherit two bundles FOSUserBundle,HWIOAuthBundle

How it possible?





Lal
lalmohan
Junior Member
 
Posts: 7
Joined: Thu Jun 28, 2012 10:49 am


Return to Bundles discussion

Who is online

Users browsing this forum: No registered users and 1 guest