Symfony3:是否可以更改表单名称? [英] Symfony3: is it possible to change the name of a form?

查看:76
本文介绍了Symfony3:是否可以更改表单名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Symfony 2.7 ,您可以使用getName()
方法在EntityType类中自定义表单名称. 现在已弃用.使用 Symfony 3.0 还有另一种方法吗?
我为需要以不同形式使用的集合提供了自定义原型entry_rows.
由于行名基于表单的名称,因此我需要更改后面的行,以便将它们用于其他表单.

With Symfony 2.7, you could customize a form's name in your EntityType class with the method getName()
This is now deprecated. Is there another way to do that with Symfony 3.0 ?
I have custom prototype entry_rows for collections that I would need to use in different forms.
Since the name of the rows is based on the form's name, I would need to change the later in order to use them with a different form.

推荐答案

您应该实现getBlockPrefix方法,而不要像迁移指南

You should implements the getBlockPrefix method instead of getName as described in the migration guide here.

例如:

/**
 * Returns the prefix of the template block name for this type.
 *
 * The block prefix defaults to the underscored short class name with
 * the "Type" suffix removed (e.g. "UserProfileType" => "user_profile").
 *
 * @return string The prefix of the template block name
 */
public function getBlockPrefix()
{
    return "form_name";
}

希望获得帮助

这篇关于Symfony3:是否可以更改表单名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆