抛出异常后,在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作为方法名称。我正在处理错误,所以在某种程度上我需要检测RESTApi正在调用哪个方法。有没有解决方案,这样我就可以检测PUT、POST和DELETE方法了。

提前谢谢。

您可以使用香草PHP;

$httpMethod = $_SERVER['REQUEST_METHOD'];

您的代码就快到了;您需要创建(或从服务管理器检索(Zend'Http'PhpEnvironment'Request的实例。

不同的是,这个类将使用$_SERVER['REQUEST_METHOD']的值,并在构造函数中设置它。

$request = new 'Zend'Http'PhpEnvironment'Request();
$method = $request->getMethod();