Symfony\Component\HttpFoundation\Request::getMethod PHP Method

getMethod() public method

If the X-HTTP-Method-Override header is set, and if the method is a POST, then it is used to determine the "real" intended HTTP method. The _method request parameter can also be used to determine the HTTP method, but only if enableHttpMethodParameterOverride() has been called. The method is always an uppercased string.
See also: getRealMethod()
public getMethod ( ) : string
return string The request method
    public function getMethod()
    {
        if (null === $this->method) {
            $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));

            if ('POST' === $this->method) {
                if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
                    $this->method = strtoupper($method);
                } elseif (self::$httpMethodParameterOverride) {
                    $this->method = strtoupper($this->request->get('_method', $this->query->get('_method', 'POST')));
                }
            }
        }

        return $this->method;
    }

Usage Example

Example #1
0
 public function indexAction(Request $request)
 {
     $debug = "DEBUG: indexAction()";
     $response = null;
     // $request  = $this->getRequest(); Symfony2
     $form = $this->createFormBuilder()->add('url', TextType::class, array('attr' => array('placeholder' => 'ef0bdd815d2a39741c4c30842b7f9488', 'class' => 'input-lg')))->getForm();
     $debug .= " ; " . print_r($request->getMethod(), true);
     if ($request->getMethod() == 'POST') {
         $debug .= " ; POST OK";
         dump("OK");
         $form->handleRequest($request);
         if ($form->isValid()) {
             $debug .= " ; FormIsValid";
             $params = array('apikey' => 'xoxo', 'url' => $form->get('url')->getData());
             // Call internal api
             $url = $this->generateUrl('tweet_count_api_url', array(), true);
             $url .= '?' . http_build_query($params);
             dump($url);
             $curl = curl_init($url);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             $response = curl_exec($curl);
             curl_close($curl);
             $debug .= " ; URL:{$url}";
             if ($response !== null) {
                 $response = json_decode($response);
             }
         }
     }
     return $this->render('TweetCountWebsiteBundle:Default:index.html.twig', array('form' => $form->createView(), 'response' => $response, 'debug' => $debug));
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getMethod