为什么在Symfony2表单中需要字段

时间:2014-12-08 07:50:18

标签: php symfony

有人可以告诉我为什么我会在表格中提交所需的文件:

<input type="checkbox" id="client_invoice" name="client[invoice]" class="invoice-controller" value="1" required="required">

如果在实体中我设置:

/**
 * @ORM\Column(type="boolean", nullable=true)
 *
 * @var boolean
 */
protected $invoice;

我的好处是因为我的表单构建者:

$builder->add('invoice', 'checkbox', array('label' => 'form.client.invoice'));

然后'required'值自动设置为true(因为add函数中的第3个参数)。我是对的,还是有其他原因需要这个领域?

1 个答案:

答案 0 :(得分:0)

默认情况下,Symfony2中需要表单字段。您可以通过以下方式为指定的表单字段关闭它:

$builder->add('invoice', 'checkbox', array(
    'label' => 'form.client.invoice',
    'required' => false,
));
相关问题