【发布时间】:2014-01-04 04:14:58
【问题描述】:
如果未提交相应的表单输入,我会遇到 symfony2 表单的问题,它会通过 null 覆盖我的实体数据。
这是一个例子:
表格类型:
$builder
->add('customerid', 'text')
->add('field1', 'text')
->add('field2', 'text')
...
控制器:
$customer = new Customer();
$customer->setId('the customerID');
$customerForm = $this->createForm(new CustomerType(), $customer);
if ($request->getMethod() == 'POST') {
$customerForm->bind($request);
...
}
在视图中,我不呈现 customerid 文本字段。 仅提交其他字段。
提交表单后,$customerForm->bind($request);即使没有为它提交空值,也会用 null 覆盖先前设置的 customerID。
如果输入字段未呈现,有什么方法可以不覆盖该值?
这似乎是同样的问题: https://github.com/symfony/symfony/issues/1341 提交了一个补丁,但我没有找到有关如何使用它的文档。
谢谢
【问题讨论】:
标签: php forms symfony symfony-forms