我有一个多表单symfony(包括)的问题。多个表单包括symfony(同一页)
我在同一页面有多篇文章,用户可以为每篇文章添加评论。我想显示添加评论的表单。
我的问题是这样的:当我提交我的评论添加表单时,Symfony不保存数据库中的信息(没有错误信息)。
我试图添加一个类来更改我的表单的名称,但它是相同的。
我的形式在控制器(由每篇文章的树枝查看通话)
public function formAction($post_id, Request $request) {
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$post = $em->getRepository('AppBundle:Post')->find($post_id);
$comment = new Comment();
$comment -> setPost($post);
$comment -> setAuthor($user);
$form_comment = $this->createForm(CommentType::class, $comment);
$form_comment->handleRequest($request);
if ($form_comment->isSubmitted()) {
$em = $this->getDoctrine()->getManager();
$em->persist($comment);
$em->flush();
$request->getSession()->getFlashBag()->add('msg_success', 'Votre contribution a bien été ajoutée');
}
return $this->render('account/form-comment.html.twig', array(
'form_comment' => $form_comment->createView(),
'post_id' => $post_id
));
}
获取名称在表单类型动作(唯一ID)
public function getName() {
return self::NAME . '_' . uniqid();
}