我无法通过symfony 2获得发布请求

时间:2015-03-30 12:53:29

标签: symfony request

我无法收到请求POST这个我的代码

public function inscriptionAction() {
    $session = $this->getRequest()->getSession();
    $request = Request::createFromGlobals();
    $myCat = new \ stdClass;

    $privatekey=$request->request->get('privatekey');
    $key=$request->request->get('key');
    if ($key== 'NULL' or $privatekey == NULL ) {
      return $this->render('GestionsFilmeBundle:public:identification.html.twig', array(
     'message' => 'Parametres non fournies-----',));
    } 
}

但privatekey和key为null

1 个答案:

答案 0 :(得分:0)

如果您使用的是Symfony Framework,则无需构建Request对象,只需将其自动注入到您的操作中,然后就可以从那里使用它。

public function inscriptionAction(Request $request) {
    $privateKey = $request->request->get('privatekey');
    $key        = $request->request->get('key');

    if (null === $key || null === $privateKey) {
        return $this->render(
            'GestionsFilmeBundle:public:identification.html.twig',
            array(
                'message' => 'Parametres non fournies-----',
            )
        );
    }
}