在 formmapper 中渲染部分树枝
Render partial twig in 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>
是否可以将其加载到我的表单映射器的选项卡中?
我认为可以做类似的事情。您想将您的形式注入基础奏鸣曲形式。这是可能的,但最后你会得到这样的东西:
<form> # form from sonata
<form> #your custom form
</form>
</form>
不推荐。
FormMaper 从 formBuilder 构建表单,您可以以标准方式定义表单字段的模板(html):
http://symfony.com/doc/current/cookbook/form/form_customization.html
我建议您覆盖奏鸣曲模板名称 'edit' 并将您的代码添加为另一种形式。
public function configure()
{
$this->setTemplate('edit', 'ApplicationM2MNewsletterBundle:CRUD:empty_form.html.twig');
}
是否可以将视图渲染到表单映射器中? 情况是这样的:
/**
* @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>
是否可以将其加载到我的表单映射器的选项卡中?
我认为可以做类似的事情。您想将您的形式注入基础奏鸣曲形式。这是可能的,但最后你会得到这样的东西:
<form> # form from sonata
<form> #your custom form
</form>
</form>
不推荐。
FormMaper 从 formBuilder 构建表单,您可以以标准方式定义表单字段的模板(html):
http://symfony.com/doc/current/cookbook/form/form_customization.html
我建议您覆盖奏鸣曲模板名称 'edit' 并将您的代码添加为另一种形式。
public function configure()
{
$this->setTemplate('edit', 'ApplicationM2MNewsletterBundle:CRUD:empty_form.html.twig');
}