Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在控制器(而不是模板)中呈现表单?我正在寻找类似的东西:
$form = $this->createForm(... $output = $form->render();
$output 将是表单的 html。
表单只是一个对象,它不知道它的布局应该是什么——这就是模板的用途。如果您在从默认控制器扩展的控制器中,则可以像这样获取渲染模板的 HTML:$html = $this->renderView('YourAppBundle:Blah:form.html.twig', array('form' => $form->createView() ) );该模板包含表单标记/渲染代码。
$html = $this->renderView('YourAppBundle:Blah:form.html.twig', array('form' => $form->createView() ) );