表单提交Symfony2中的HTTP状态代码 [英] HTTP status code in form submission Symfony2

查看:115
本文介绍了表单提交Symfony2中的HTTP状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Symfony2和树枝的应用程序。我想从模板提交一个值给控制器,这个值是使用模板中的Jquery函数设置的。我为此使用了表单和隐藏类型字段。这是我的控制器代码:

I am developing an application using Symfony2 and twig. I want to submit a value to the controller from a template, this value is set using a Jquery function in the template. I am using a form and a hidden type field for this. This is my controller code:

public function testuaanotatuAction(Request $request)
    { 
             $Interpretatzea = new Interpretatzea();
             $Interpretatzea->setMarkagarriaInterpretatua($Markagarria);
             $form = $this->createFormBuilder($Interpretatzea)
                               ->add('MarkInterpretazioak', 'hidden')
                               ->getForm();

             $Erantzuna = $this->getRequest(); 

             if ($Erantzuna->getMethod() == 'POST') 
             {
               $form->bindRequest($Erantzuna);

             if ($form->isValid()) 
             {
                   return $this->redirect($this->generateUrl('AnotatzaileaAnotatzaileaBundle_FAQ'),
                                   array('proba' => $form->get('MarkInterpretazioak')));
                 }
             }

             //Anotatzeko galderaren interfazeari deitu eta azpimarratu beharreko markagarriaren MarkIdent-a pasatu
             return $this->render('AnotatzaileaAnotatzaileaBundle:Page:AnotatuInterpretazio.html.twig',
                                   array('form' => $form->createView()));

}

public function FAQAction($proba)
{
  return $this->render('AnotatzaileaAnotatzaileaBundle:Page:FAQ.html.twig',array('proba' => $proba));
}

,这是模板AnotatuInterpretazio.html.twig的一部分,值使用下一个JQuery函数隐藏字段:

and this is part of the template AnotatuInterpretazio.html.twig where I assign the value to the hidden field using the next JQuery function:

   <form action="{{ path('AnotatzaileaAnotatzaileaBundle_testuaanotatu') }}" method="post" {{ form_enctype(form) }} class="erreg">
        {{ form_widget(form) }}

        <input type="submit" value="Egina" />
    </form>

 <!--   <a href="{{ path('AnotatzaileaAnotatzaileaBundle_testuaanotatu') }}"><button id="Egina_Botoia">Egina</button></a><br /> -->


    <script type='text/javascript'>
      $("MatchedTag").click(function () 
                             {
                   $(this).toggleClass("highlight");
                               var Erantzuna = this.id;
                               $('#hiddenval').val('this.id');//Assigning the value   
                         });
          </script>

浏览器显示下一个错误:

The browser shows the next error:

The HTTP status code "Array" is not valid.
500 Internal Server Error - InvalidArgumentException

任何想法为什么会这样?

Any idea why can it be?

推荐答案

错误在这里:

The error is here:

return $this->redirect(
    $this->generateUrl('AnotatzaileaAnotatzaileaBundle_FAQ'),
    array('proba' => $form->get('MarkInterpretazioak'))
);

我将其格式化为更明显。您将数组作为 render()(HTTP状态码)的第二个参数传递,而不是将它传递给 generateUrl()

I reformatted it to be more obvious. You're passing the array as the second parameter of render() (the HTTP status code) instead of passing it to generateUrl().

这篇关于表单提交Symfony2中的HTTP状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆