0

我想在主页上提交评论,然后重定向到这个页面。这是我的行动:

public function submitcommentAction(Request $request)
{
    $user=$this->get('security.context')->getToken()->getUser();
       $uid=$user->getId();

    $comment=new comment();

    //$comment->setCafe();

    $form=$this->createFormBuilder($comment)
            ->add('cafe','hidden')
            ->add('description','textarea')
            ->getForm();
    if($request->getMethod()=='POST')
    {
        $form->bind($request);

        if($form->isValid())
        {
            $comment->setCafe($form['cafe']->getData());
            $comment->setUser($uid);
            $comment->setDescription($form['description']->getData());
            $em=$this->getDoctrine()->getEntityManager();
            $em->persist($comment);
            $em->flush();
              // return $this->redirect($this->generateUrl('showcofe'));   
            var_dump($em);
    exit();

        }
    }

                    $r='error';
        return $this->      render('CafeManagementBundle:Default:simple.html.twig',array('r'=>$r));

}

这是我的树枝:

    <div class="new-comment">
      <div class="new-comment-text"> :your comment
        <div>
          <form id="comment-form" method="post" action={{path('subcomment')}}" {{form_enctype(form1)}}">
            <ul class="smallbuttons">

                <input type="hidden" id="form_cafe" name="form[cafe]" value="{{cafe.id}}" />
                  {{form_widget(form1.description)}}
                <div style="display:none">{{ form_rest(form1) }}</div>

         <p><a id="clickbotton1"     href="javascript:document.getElementById('form1').submit()" class="btn_smallorange edit2">submit</a></p> 
            </ul>
          </form>
        </div>
      </div>
    </div>

我不知道如何将隐藏字段(咖啡馆)传递给控制器​​。另外,请您告诉我,我的控制器是否正确?

4

0 回答 0