简体   繁体   English

使用Symfony2中的数据预填充表单,方法更短

[英]Prefill form with data in Symfony2, shorter way

I have form that can be used on front page and search page. 我有可以在首页和搜索页上使用的表格。 Users can fill it on both pages, but if it is filled on front page it has to show filled data on the search page. 用户可以在两个页面上都填充它,但是如果在首页上填充它,则必须在搜索页面上显示填充的数据。 to achieve this I'm forwarding the data, and using syntax similar to this. 为此,我正在转发数据,并使用与此类似的语法。

$form->get('field')->setData($form_data['field']);

Everything works fine, except the form has a lot of fields and I was wondering if there is a shorter way to achieve the same? 一切工作正常,除了表单有很多字段,我想知道是否有更短的方法来实现相同的目的?

What about this? 那这个呢?

$form_data['return_box'] = (boolean)$form_data['return_box'];
$form->setData($form_data);

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

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