Php Apigility获取资源名称和请求方法类型
如何在Apigility中获取资源名称? 我试过了Php Apigility获取资源名称和请求方法类型,php,zend-framework2,laminas-api-tools,zend-framework3,Php,Zend Framework2,Laminas Api Tools,Zend Framework3,如何在Apigility中获取资源名称? 我试过了 $route=$event->getRouteMatch() 但若资源名称包含的名称超过了名称,则将其拆分 例如,如果重新使用名称“employeeVerifySomething”,则返回“employee.verify.something”? 此外,我还需要获取请求类型以区分get-in“fetch&&fetch-all”的要点:“我还需要获取请求类型以区分get-in“fetch&&fetch-all” 对于fetchall,有条件的话,可
$route=$event->getRouteMatch()代码>
但若资源名称包含的名称超过了名称,则将其拆分
例如,如果重新使用名称“employeeVerifySomething”,则返回“employee.verify.something”?
此外,我还需要获取请求类型以区分get-in“fetch&&fetch-all”的要点:“我还需要获取请求类型以区分get-in“fetch&&fetch-all”
对于fetchall,有条件的话,可以覆盖fetchall方法
$client = new \Zend\Http\Client($uri);
$client->setMethod('GET');
$client->setParameterGet(['id'=>1]);
//Or
$client->setParameterGet([]);
用于获取一个或获取方法
在url后添加id:
$uri.'/'.$id;
您可以在module.config.php
的onBootstratp()方法中找到它们
public function onBootstrap(MvcEvent $e)
{
$request = $e->getRequest();
// Get the request method
$method = $request->getMethod();
// Get the path according to your format
$path = $request->getUri()->getPath();
$parts = explode('/', $path);
if (!empty($parts)) {
foreach ($parts as $part) {
$words = preg_split("/((?<=[a-z])(?=[A-Z])|(?=[A-Z][a-z]))/", $part);
if (!empty($words)) {
$words = array_filter($words, function($value, $key){
return !empty($value);
}, ARRAY_FILTER_USE_BOTH);
$words = array_map('strtolower', $words);
}
$paths[] = join('.', $words);
}
}
// Here is the formatted path
$path = join("/", $paths);
echo $method; // Outputs the requested method for example, GET
echo $path; // Outputs employee.verify.something against employeeVerifySomething
}
/hunkey.punkey/munkey.dunkey.chunkey