FOSUserBundle with relation another entity

168 views
Skip to first unread message

Francesco

unread,
Feb 22, 2012, 10:40:05 AM2/22/12
to FriendsOfSymfony Developer
I related my acme / userbundle with another entity, now I need to
write to the database for userbundle and for the other entity at the
same time, so I overwrote the controller RegistrationController.php
and I added these lines
namespace Acme\UserBundle\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as
BaseController;
use Acme\TestBundle\Entity\Test;

/+++++++/
if ($process) {
$user = $form->getData();
$test = new Test();
$test->setUser($user);
$test->setName('Name test');

$em = $this->getDoctrine()-
>getEntityManager();<-----------------------LINE 25

$em->persist($test);
$em->flush();
/*****************************************************
* Add new functionality (e.g. log the registration) *
*****************************************************/
/+++++++/

Fatal error: Call to undefined method Acme\UserBundle\Controller
\RegistrationController::getDoctrine() in /home/marcello/Progetti/
Symfony/src/Acme/UserBundle/Controller/RegistrationController.php on
line 25

How can i write into database in contemporany with registration
fosuserbundle?thx

Ryan Weaver

unread,
Feb 22, 2012, 11:35:11 AM2/22/12
to friendsofs...@googlegroups.com
Hi there!

The normal getDoctrine method is just a shortcut in the optional, but standard base controller class. The FOS controllers don't extend the base controller, so you just don't have access to those same shortcut methods.

The best thing to do is to take a look at the base Controller class inside symfony and see what each method actually does. For example, getDoctrine is equivalent to:

$this->container->get('doctrine')

Good luck!

Ryan

Francesco

unread,
Feb 24, 2012, 3:26:57 AM2/24/12
to FriendsOfSymfony Developer
excuse me how I should do to save more data in another table, in
conjunction with user?

i must extend controller RegistrationController od fosuserbundle?
and i must insert the logic into this file?

I knew all logic, i must insert inside controller....
can u show me an pratical example?thx
Reply all
Reply to author
Forward
0 new messages