【发布时间】:2014-03-07 14:15:10
【问题描述】:
我有一个实体“组”,有名称和描述。
我创建了一个用于更新两者的表单,但是当我单击提交时,值设置为NULL。
我还尝试创建一个新实体。但在这种情况下,它们的值在字段中设置为默认值。
这是我的代码:
我的表格:
<form method="post" class="form-signin" {{ form_enctype(form) }}>
<input id="name" name="form[name]" required="required" value="{{ group.name }}"></input>
<textarea id="description" name="form[description]" >{{ group.description }}</textarea>
<input class="btn btn-lg btn-primary btn-block" type="submit" id="_submit" name="_submit" value="submit" />
</form>
我的控制器:
public function updateParametersAction()
{
$user = $this->get('security.context')->getToken()->getUser();
$repository = $this->getDoctrine()
->getManager()
->getRepository('MyBundle:Groups');
$group = $repository->findOneByIdUser($user->getId());
$form = $this->createFormBuilder($group)
->add('name', 'text')
->add('description', 'textarea')
->getForm();
$request = $this->get('request');
if ($request->getMethod() == 'POST') {
$em = $this->getDoctrine()->getManager();
$em->persist($group);
$em->flush();
}
return $this->render('MyBundle:Client:updateParameters.html.twig', array(
'group' => $group,
'form' => $form->createView()
));
}
怎么了?
【问题讨论】:
标签: php symfony entity twig bundle