简体   繁体   English

Symfony2:如何使form_rest(form)不显示字段

[英]Symfony2: How to make form_rest(form) not to display a field

There is something I don't like. 我有什么不喜欢的 I really hate how ugly it renderizes a date choice filed (with the three selects). 我真的很讨厌它使提交的日期选择(包括三个选择)多么丑陋。 I don't find the way to make those huge unstyled selects to be displayed fitting my own style (or the style of my site). 我找不到使那些庞大的无样式选择适合我自己的样式(或我网站的样式)的显示方式。

So, two possibilities (and questions): 因此,有两种可能性(和问题):

  • How and where would I change that "choice" date type to make it more beautiful? 我将如何以及在何处更改“选择”日期类型以使其更美观?
  • If not possible or if too difficult, how and where would I tell the engine for it not to display a certain field (in this case that date)? 如果不可能或太困难,我如何以及在什么地方告诉引擎不要显示某个字段(在这种情况下为该日期)?

I know I can manually display each field omitting the one I don't want to appear. 我知道我可以手动显示每个字段,而忽略不想显示的字段。 But how about the opposite? 但是相反呢? ie telling symfony to display all of the fields but one? 即告诉symfony显示所有字段,但只有一个?

At first, Symfony allow you to choose between different widgets and formats for your date or datetime field. 首先,Symfony允许您在日期或日期时间字段的不同窗口小部件和格式之间进行选择。 Those are described here : http://symfony.com/doc/current/reference/forms/types/date.html#widget . 此处介绍了这些内容: http : //symfony.com/doc/current/reference/forms/types/date.html#widget

The options to edit the field are in the class 'YourEntityType', located in the 'ROOT/TO/YOUR/BUNDLE/Form' directory. 编辑该字段的选项位于类“ YourEntityType”中,位于“ ROOT / TO / YOUR / BUNDLE / Form”目录中。

Example: 例:

public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('datefield', null, array('widget' => 'single_text'));
}

The two possibility you propose are also possible. 您提出的两种可能性也是可能的。

  1. For the first possibility, you should check the documentation about how to custom form. 对于第一种可能性,您应该查看有关如何自定义表单的文档。 http://symfony.com/doc/current/cookbook/form/form_customization.html http://symfony.com/doc/current/cookbook/form/form_customization.html

I would say that you might create you own field type which will have date_time field as parent. 我想说,您可以创建自己的字段类型,并将date_time字段作为父字段。

  1. It is also possible to delete the field 'date'. 也可以删除“日期”字段。

In your controller : 在您的控制器中:

$form = $this->createForm(new EntityType(), $entity);
$form->remove('name of your field in the entity');

Or in the EntityType class : 或在EntityType类中:

public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('onefiled');
        $builder->add('datefield'); //this is the line you must delete
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM