dpzff20644 2012-10-29 15:58
浏览 34
已采纳

在Symfony2上调用未定义的方法isMethod

Here is my problem I'm following the symfony tutorial (Handling form submission) but I've the error "Call to undefined method Symfony\Component\HttpFoundation\Request::isMethod()" and I can't fix it. I read in some website that isMethod was suppressed, but I can't find another way to perform my check. Thanks.

use Symfony\Component\HttpFoundation\Request;

public function contactusAction(Request $request)
    {   
    $contact = new ContactUs(); 
    $form = $this->createFormBuilder($contact)
        ->add('nom', 'text')
        ->add('mail', 'email')
        ->add('sujet', 'choice', array('choices' => array('pt' => 'Problemes techniques', 'bi' => 'Boite a idees', 'd' => 'Divers')))
        ->add('msg', 'textarea')
        ->getForm();

    if ($request->isMethod('post')) 
    {
        $form->bind($request);

        if ($form->isValid()) 
        {
            echo 'OK!';         
            //return $this->redirect($this->generateUrl('task_success'));
        }
        else
            echo 'KO!!';
        }

    return $this->render('MyCoreBundle:Info:contactus.html.twig', array('form' => $form->createView()));
        //return array();
    }}
  • 写回答

1条回答 默认 最新

  • douzhi3454 2012-10-29 16:07
    关注

    Update Symfony to the recent version or use

    if ('POST' === $request->getMethod())
    

    Also, be aware that the compared method string should be in uppercase.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo