我有一个入口点控制器(editAction),它根据路径变量({property})显示不同的模板。我正在使用注释“@Template”。
我尝试了很多不同的设置,但都没有。我得到的结论是以下内容:
错误是“合并过滤器仅适用于数组或散列”
public function editAction(Request $request, $property, $id)
{
// controller logic
$form = $this->createForm('ObjectEdit'.ucfirst($property), $object);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($product);
$em->flush();
return $this->redirect($this->generateUrl('acme-demo-dashboard-show'));
}
$response = $this->forward('AcmeDemoBundle:Dashboard:edit'. ucfirst($property),
array('form' => $form)
);
return $response;
}
/**
* Edit Title property for Object
* @Template
*/
public function editTitleAction($form)
{
return array('form' => $form->createView());
}
Yaml路由:
acme-demo-dashboard-edit:
path: /dashboard/edit/{property}/{id}
defaults: { _controller: AcmeDemoBundle:Dashboard:edit }
requirements:
acme-demo-dashboard-edit-title:
path: /dashboard/forward/edit/title/{form}
defaults: { _controller: AcmeDemoBundle:Dashboard:editTitle }
编辑:有关错误的更多信息:
at twig_array_merge (null, array('_locale' => 'en'))
Edit2:editTitle的Twig模板
{% extends "AcmeDemoBundle::layout.html.twig" %}
{% trans_default_domain "AcmeDemoBundle" %}
{% block AcmeBundleContent %}
<div class="col-sm-12">
<div class="alert alert-info">
{{ (ycRoute~'.intro') | trans }}
</div>
{{ form_start(form, { 'attr': {'class': 'form-horizontal', 'role': 'form'}}) }}
{% if form_errors(form) %}
<div class="alert alert-danger">
{{ form_errors(form) }}
</div>
{% endif %}
<div class="form-group {% if form_errors(form.title) %}has-error{% endif %}">
{{ form_label(form.title, '', {'label_attr': {'class': 'col-sm-3 control-label'}}) }}
<div class="col-sm-9">
{{ form_widget(form.title, { 'attr': {'class': 'form-control', 'placeholder': (ycRoute~'.titre') } }) }}
<p class="help-block">{{ form_errors(form.title) }}</p>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
{{ form_widget(form.save, { 'attr': {'class': 'btn btn-primary'} }) }}
</div>
</div>
<div class="row">
<div class="col-sm-9 col-sm-offset-3">
(<i class="fa fa-asterisk yc-fa-sm"></i>) {{ (ycRoute~'.champRequis')|trans }}
</div>
</div>
{{ form_end(form)}}
</div>
{% endblock AcmeBundleContent %}
答案 0 :(得分:0)
您是否尝试过这种语法来渲染模板?您需要删除@Template注释。
return $this->render(
'AcmeDemoBundle:Dashboard:edit'. ucfirst($property),
array('form' => $form)
);
&#34;向前&#34;用于将请求转发给另一个控制器。