是否可以将视图渲染到formmapper中? 情况是这样的:
/**
* @param FormMapper $formMapper
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->tab('Company')
->with('Info')
->add('name')
->end()
->end()
->tab('Abonnementen')
->with('Abonnementen', array('class' => 'col-md-12'))
//Render a partial twig here
->end()
;
}
这是在我的树枝上:
<form class="form-horizontal" action="" method="post" style="margin-top:15px;">
<div class="row">
<div class="col-md-12">
<div class="box box-primary">
<div class="box-header"><h4 class="box-title">Abonnementen</h4></div>
<div class="box-body">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Active</th>
</tr>
</thead>
<tbody>
{% for abonnement in abonnementen %}
<tr>
<td>{{ abonnement.name }}</td>
<td>{{ abonnement.description }}</td>
<td>€ {{ abonnement.price }}</td>
<td>
<input type="checkbox" name="{{ abonnement.id }}[active]"
{% if abonnement.active %}
checked="checked"
{% endif %}>
</td>
</tr>
{% endfor %}
<tr>
<td colspan="4">
<input type="submit" class="btn btn-primary" value="Save" name="abonnement_save">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</form>
是否可以将其加载到我的formmapper中的标签中?
答案 0 :(得分:1)
我认为可以做类似的事情。您希望将表单注入基本奏鸣曲表单。这是可能的,但最后你得到这样的东西:
<form> # form from sonata
<form> #your custom form
</form>
</form>
我不推荐它。
formBuper的formmaper构建表单,你可以用标准方式定义表单字段的模板(html):
http://symfony.com/doc/current/cookbook/form/form_customization.html
我建议您覆盖奏鸣曲模板名称'edit',并将您的代码添加为另一种形式。
public function configure()
{
$this->setTemplate('edit', 'ApplicationM2MNewsletterBundle:CRUD:empty_form.html.twig');
}