我有这样的表格:
->add('task', 'text')
->add('dueDate', 'date')
->add('save', 'submit')
我想使用数据库中的数据迭代输入文本/复选框。
[更新]换句话说我想根据数据库中的数据打印字段。 像foreach一样,但都使用symfony形式($ result as $ val){print'input type =“checkbox”value =“valore”'}
你能帮助我吗?
答案 0 :(得分:0)
您正在寻找的可能是表单构建器:http://symfony.com/doc/current/book/forms.html#building-the-form
//In your controller
$results = //get data from the database here
$form = $this->createFormBuilder();
foreach($results as $result){
$form->add($result['field_name'],$result['field_type'],array('data=>$result['field_value']'));
//Where field_name would be something like task, dueDate, save, etc.
// field_type would be something like, text, choice, hidden
//then to set the data for the field you pass it in the data option aka field_value
}
$form->getForm()->createView;