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

查看:21
本文介绍了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 方法而不是 getName ,如迁移指南中所述这里.

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天全站免登陆