Symfony项目; SonataUser,FOSUser及其registration_content.html.twig

时间:2014-03-31 14:17:37

标签: symfony twig fosuserbundle user-registration sonata-user-bundle

已解决 - 请参阅条目底部

我正在努力熟悉扩展FOSUserBundle的SonataUserBundle。

安装工作正常(据我所知),现在我想自定义 登录和注册表格。 我在app / Resources中覆盖了模板并且工作正常。 但是,对于注册表格,我不明白它为什么会起作用......

这是我的问题:

SonataUserBundle注册控制器(RegistrationFOSUser1)设置表单 并使用FOSUserBundle呈现它:注册:register.html.twig作为模板:

$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包含FOSUserBundle:注册:register_content.html.twig:

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

register_content.html.twig包含用于呈现表单的树枝代码。

然而,实际呈现的是SonataUserBundle:注册:register_content.html.twig

我无法弄清楚SonataUserBundle在何处,何时以及如何替代FOSUserBundle ......

感谢任何提示!


好的,我现在看到我的问题的解决方案在symfony cookbook中有详细记录: http://symfony.com/doc/current/cookbook/bundles/inheritance.html

对于那些像我一样对symfony不熟悉的人:

如果为另一个包'ChildBundle'定义父'ParentBundle',则每次调用ParentBundle中的函数,模板等时,symfony将首先查看ChildBundle中是否存在具有相同名称的文件。

父包在ChildBundle.php中定义:

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

只要通过通常的ParentBundle:path:file notation调用父包的文件,这是可行的。

1 个答案:

答案 0 :(得分:1)

好的,我现在看到我的问题的解决方案在symfony cookbook中有详细记录:http://symfony.com/doc/current/cookbook/bundles/inheritance.html

对于那些像我一样对symfony不熟悉的人:

如果为另一个包'ChildBundle'定义父'ParentBundle',那么每次调用ParentBundle中的函数,模板等时,symfony将首先查看ChildBundle中是否存在具有相同名称的文件。

父包在ChildBundle.php中定义:

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

只要通过通常的ParentBundle:path:file notation调用父包的文件,这是可行的。