I need to detect the HTTP method name from module.php file. For this i have tried following code which only gives me GET method,
use Zend\Http\Request;
$getRequest = new Request();
$httpMethod=$getRequest->getMethod();
But in $httpMethod variable i am only getting GET as method name. I am handling errors so in a way i need to detect the which method is being called by my REST Api. Is there any solution for this so i can detect PUT,POST and DELETE method also.
Thanks in advance.
You can use vanilla PHP;
$httpMethod = $_SERVER['REQUEST_METHOD'];
Your code is almost there; you need to create (or retrieve from the service manager) a instance of Zend\Http\PhpEnvironment\Request
.
The difference is that this class will use the value of $_SERVER['REQUEST_METHOD']
and set it within the constructor.
$request = new \Zend\Http\PhpEnvironment\Request();
$method = $request->getMethod();