Solved -- see bottom of entry

I'm trying to get familiar with the SonataUserBundle extending the FOSUserBundle.

The installation worked fine (as far as I can tell) and now I want to customize the login and registration forms. I overwrote templates in app/Resources and it worked fine. However, for the registration form I do not understand why it works...

Here's my problem:

The SonataUserBundle registration controller (RegistrationFOSUser1) sets up the form and renders it with FOSUserBundle:Registration:register.html.twig as template:

$form = $this->container->get('sonata.user.registration.form');
$formHandler = $this->container->get('sonata.user.registration.form.handler');
[...]
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
        'form' => $form->createView(),
    )); 

register.html.twig includes FOSUserBundle:Registration:register_content.html.twig:

{% block fos_user_content %}
{% include "FOSUserBundle:Registration:register_content.html.twig" %}
{% endblock fos_user_content %}

register_content.html.twig contains the twig code to render the form.

However, what is actually rendered is SonataUserBundle:Registration:register_content.html.twig

I just can't figure out where, when and how SonataUserBundle substitutes FOSUserBundle here...

Thanks for any hints!


Ok, I now see that the solution to my question is well documented in the symfony cookbook: http://symfony.com/doc/current/cookbook/bundles/inheritance.html

For those as new to symfony as myself:

If you define a parent 'ParentBundle' for another bundle 'ChildBundle', then everytime a function, template etc. from ParentBundle is called, symfony will first look whether there is a file with the same name in ChildBundle.

The parent bundle is defined in the ChildBundle.php:

public function getParent()
{
    return 'ParentBundle';
}

This works, as long as the file of the parent bundle is called via the usual ParentBundle:path:file notation.

有帮助吗?

解决方案

Ok, I now see that the solution to my question is well documented in the symfony cookbook: http://symfony.com/doc/current/cookbook/bundles/inheritance.html

For those as new to symfony as myself:

If you define a parent 'ParentBundle' for another bundle 'ChildBundle', then everytime a function, template etc. from ParentBundle is called, symfony will first look whether there is a file with the same name in ChildBundle.

The parent bundle is defined in the ChildBundle.php:

public function getParent()
{
return 'ParentBundle';
}

This works, as long as the file of the parent bundle is called via the usual ParentBundle:path:file notation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top