我有一个数据表,我希望能够逐行编辑。最明智的做法是让每一行成为自己的形式。我可以在没有链接父实体的Symfony2 中执行此操作吗? documentation仅显示如何与父母进行此操作。
答案 0 :(得分:1)
您的控制器操作:
public function gridAction( $criteria ) {
$entities = $this->getDoctrine()
->getManager()
->getRepository( 'Bundle:Entity' )
->findbyCriteria( $criteria );
// criteria presumably involves some gneration from routing
// and may not be a parameter at all
if ( array() != $entities->toArray() ) {
throw
$this->createNotFoundException( 'Unable to find any entities.' );
}
$forms = array_map(function($element) use ($this) {
return $this->createForm(new EntityType()
, $element
, array() // form parameters here
);
});
return $this->render( 'Bundle:Entity:grid.html.twig'
, array(
'forms' => $forms
) );
}
你的树枝:
<table class="records_list dataTable" id="CaseloadTable">
<thead>
<tr>
</tr>
</thead>
<tbody>
{% for form in forms %}
<tr>
{{form_widget(form)}}
</tr>
{% endfor %}
</tbody>
</table>
但是,你可能会更好地看待这个: https://github.com/Abhoryo/APYDataGridBundle