抛出异常后检测 zend module.php 中的 HTTP 方法名称
detect HTTP method name in module.php of zend after exception has thrown
我需要从 module.php 文件中检测 HTTP 方法名称。为此,我尝试了以下代码,它只给我 GET 方法,
use Zend\Http\Request;
$getRequest = new Request();
$httpMethod=$getRequest->getMethod();
但是在 $httpMethod 变量中我只得到 GET 作为方法名。我正在处理错误,所以在某种程度上我需要检测我的 REST Api 正在调用哪个方法。是否有任何解决方案,以便我也可以检测 PUT、POST 和 DELETE 方法。
提前致谢。
你可以使用原版 PHP;
$httpMethod = $_SERVER['REQUEST_METHOD'];
你的代码快写好了;您需要创建(或从服务管理器中检索)Zend\Http\PhpEnvironment\Request
的实例。
不同的是这个class会use the value of $_SERVER['REQUEST_METHOD']
and set it within the constructor.
$request = new \Zend\Http\PhpEnvironment\Request();
$method = $request->getMethod();
我需要从 module.php 文件中检测 HTTP 方法名称。为此,我尝试了以下代码,它只给我 GET 方法,
use Zend\Http\Request;
$getRequest = new Request();
$httpMethod=$getRequest->getMethod();
但是在 $httpMethod 变量中我只得到 GET 作为方法名。我正在处理错误,所以在某种程度上我需要检测我的 REST Api 正在调用哪个方法。是否有任何解决方案,以便我也可以检测 PUT、POST 和 DELETE 方法。
提前致谢。
你可以使用原版 PHP;
$httpMethod = $_SERVER['REQUEST_METHOD'];
你的代码快写好了;您需要创建(或从服务管理器中检索)Zend\Http\PhpEnvironment\Request
的实例。
不同的是这个class会use the value of $_SERVER['REQUEST_METHOD']
and set it within the constructor.
$request = new \Zend\Http\PhpEnvironment\Request();
$method = $request->getMethod();