在與ViciousAmateur相關的視圖中:默認:索引控制器/ acction我想添加一個表格來篩選分頁結果(KnpPaginatorBundle)。在我的控制器中,我創建窗體並返回帶有窗體變量的視圖。 (啊..如果我把表格直接放在視圖中,按預期工作)。如何將窗體視圖放入繼承的樹枝視圖中?
/**
* @Route("/{page}", defaults={"page" = 1}, name="homepage")
* @Route("/")
* @Template()
*/
public function indexAction(Request $request, $page)
{
$filters = new Filters();
$form = $this->createForm(new FiltersType(), $filters);
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
// Do something with form submited data
}
}
// Do something when index action loads, pagination etc...
return $this->render('ViciousAmateurBundle:Default:index.html.twig', array(
'form' => $form->createView(),
'pagination' => $pagination
)
);
}
但是,如果我嘗試把形式進入樹枝包括(以使視圖繼承/獨立)的表單變量傳遞給該視圖...那麼它不會工作。我得到這個迴應「錯誤101(net :: ERR_CONNECTION_RESET):Se ha restablecido laconexión。」(有些詞在西班牙語)這是我的觀點:從指數
// file: ViciousAmateurBundle:Default:index.html.twig
{% extends '::base.html.twig' %}
{% block body %}
{{ include('ViciousAmateurBundle:Default:filters.html.twig', {'form': form}) }}
{% block filters %}
{% endblock %}
// Stuff in the body
{% endblock %}
正如你可以看到,表單視圖是繼承(擴展的條款)和代碼添加到它的「過濾器」樹枝塊...
// file: ViciousAmateurBundle:Default:filters.html.twig
{% extends 'ViciousAmateurBundle:default:index.html.twig' %}
{% block filters %}
<section class="filters">
<form action="{{ path('homepage') }}" method="post" {{ form_enctype(form) }} class="filters">
{{ form_errors(form) }}
{{ form_errors(form.country) }}
{{ form_widget(form.country, { 'attr': { 'placeholder': 'País', 'class': 'input-block-level' } }) }}
// Some more form fields...
{{ form_rest(form) }}
<input type="submit" class="filters_submit btn btn-large btn-block" />
</form>
</section>
{% endblock %}
然後...有可能做那件事嗎?把表單放在一個繼承的視圖(從索引的過濾器視圖)傳遞給它的控制器給出的表單變量?它應該工作?我失蹤或做錯了什麼?謝謝
這裏的嘗試呈現頁面後我dev.log。 http://pastebin.com/raw.php?i=RsKsWqnf – Jeflopo 2013-02-09 22:00:25