我是 Symfony2 / twig 的新手,我需要使用预先保存的值渲染一个表单。
我可以让表单加载/保存数据,但我不能让它显示预先保存的值。我错过了什么?
这是我的控制器代码:
/**
* @Route("/build/{id}")
* @Template()
*/
public function buildAction($id)
{
$request = $this->getRequest();
$em = $this->getDoctrine()->getEntityManager();
$repo = $em->getRepository('ImagineNewsletterBundle:Section');
$section = $repo->find($id);
$newsletter = $section->getNewsletter();
$globalMag = $newsletter->getMagazine();
//$globalMag = unserialize($globalMag[0]);
$builder = $this->get('newsletter.builders')->getBuilder($section->getBuilder());
$builder->setSearchUrl($this->generateUrl('imagine_newsletter_section_search', array('builder' => $section->getBuilder())));
$form = $this->createForm($builder->getSearchFormBuilder());
$prevArticles = $section->getArticles();
// $form->bind($prevArticles);
return $this->render('ImagineNewsletterBundle:Section:'.$builder->getTemplate() , array('prevArticles' => $prevArticles,'builder' => $builder, 'form' => $form->createView(), 'section' => $section, 'newsletter' => $newsletter, 'globalmag' => $globalMag));
}
这是我的树枝/表单代码:
<form id="advert" action="{{ addAticle }}" method="post" {{ form_enctype(form) }} class="form-stacked">
<div class="form_element">
{{ form_label(form.topLogoAdvert) }}
{{ form_errors(form.topLogoAdvert) }}
{{ form_widget(form.topLogoAdvert) }}
</div>
<div class="form_element">
{{ form_label(form.topLogoAlt) }}
{{ form_errors(form.topLogoAlt) }}
{{ form_widget(form.topLogoAlt) }}
</div>
<div class="form_element">
{{ form_label(form.topLogoLink) }}
{{ form_errors(form.topLogoLink) }}
{{ form_widget(form.topLogoLink) }}
</div>
<input type="hidden" name="section" value="{{ section.id }}" />
{{ form_widget(form) }}
<div class="well">
<button type="submit" class="btn primary">Save</button>
<button id="reset" type="reset" class="btn">Reset</button>
</div>
{{ form_rest(form) }}
</form>