If your controller is extending the "base" registration controller from FOSUserBundle (e.g. FOS\UserBundle\Controller\RegistrationController
) then you have a ContainerAware
object, but as you point out, not the base Symfony controller which provides certain convenience methods.
The base controller's getDoctrine()
method simply is a convenience method to return the doctrine service from the container, e.g.
public function getDoctrine()
{
if (!$this->container->has('doctrine')) {
throw new \LogicException('The DoctrineBundle is not registered in your application.');
}
return $this->container->get('doctrine');
}
So to answer your questions:
- Either add a convenience method to your
RegistrationController
, similar to the above, or simply replace calls to$this->getDoctrine()
with a call to return thedoctrine
service from the container. - Yes, if you've got a different view which you would like to render, what you've done is perfectly acceptable.
As an alternative though, you can simply extend the FOSUserBundle
with your own, as it appears that you may have already done, by specifying the FOSUserBundle
as the parent to your bundle, e.g.
class MyUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
Doing this should allow you to simply override the resources by placing your custom views like register.html.twig
(if you're using twig) in the same location as those found in the source bundle. This way you can keep the behavior without having to modify controllers and, at the same time, customize your views.
Of course, if you need additional business logic, or need to do anything custom, you will probably have to override the controller any way.