Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 如何覆盖FOS用户包表单标签_Symfony_Symfony Forms_Fosuserbundle - Fatal编程技术网

Symfony 如何覆盖FOS用户包表单标签

Symfony 如何覆盖FOS用户包表单标签,symfony,symfony-forms,fosuserbundle,Symfony,Symfony Forms,Fosuserbundle,我很难覆盖用于Symfony2的FOS用户包使用的标签 我已经覆盖了Form类,但是像“setOption”这样的元素没有选项,只有getter 我可以删除一个元素,然后用合适的标签再次添加它,但这似乎有点过分了。有没有什么好方法可以覆盖表单元素上的选项,或者只覆盖翻译键?您不需要覆盖表单类 复制/粘贴app/Resources/translations目录中的vendor/friendsofsymfony/user bundle/FOS/UserBundle/Resources/transla

我很难覆盖用于Symfony2的FOS用户包使用的标签

我已经覆盖了Form类,但是像“setOption”这样的元素没有选项,只有getter


我可以删除一个元素,然后用合适的标签再次添加它,但这似乎有点过分了。有没有什么好方法可以覆盖表单元素上的选项,或者只覆盖翻译键?

您不需要覆盖表单类

复制/粘贴
app/Resources/translations
目录中的
vendor/friendsofsymfony/user bundle/FOS/UserBundle/Resources/translations/FOSUserBundle.xx.yml
文件(具有相同的目录结构和相同的文件名),并根据您的方便重新定义翻译


编辑:正如@mario johnathan所说,覆盖翻译不是包继承的一部分。有关官方文档,请参见:
app/Resources/translations

但是如果您在父捆绑包(
src/MyAppBundle/Resources/translations
)或任何其他捆绑包中重写它,请确保在内核中重写的捆绑包之后加载捆绑包:

public function registerBundles()
{
    $bundles = [
        ...
        new FOS\UserBundle\FOSUserBundle(),
        new MyAppBundle\MyAppBundle(),
        ...
    ];
...
}

实际上,我必须将其复制到app/Resources/FOSUserBundle/translation中,而不是我的bundle dir中才能使其工作,请注意,要使其工作,您必须在框架的
config.yml
中启用翻译,即:framework:translator:{fallback:“%locale”},并注意您需要清除缓存(php-app/console-cache:clear)如果您更改了,请重新加载翻译。我使用的是SF2.8,放置文件的正确路径是app/Resources/translations/FOSUserBundle.xx。yml@MarioJohnathan非常感谢。作品