[英]Apigility get Resource name and request method type
如何在Apigility中获取资源名称? 我试过了
$route = $event->getRouteMatch();
但是如果资源名称包含的名称多于名称,则将其除以。
另外,我还需要获取请求类型,以区分“获取和&获取所有”中的获取
对于这一点:“此外,我还需要获取请求类型以区分在获取和获取所有内容中获取”
对于全部获取,如果有条件,则可以覆盖全部获取方法
$client = new \Zend\Http\Client($uri);
$client->setMethod('GET');
$client->setParameterGet(['id'=>1]);
//Or
$client->setParameterGet([]);
用于获取一种或获取方法
在网址后添加ID:
$uri.'/'.$id;
您可以在onBootstratp()
方法中进行module.config.php
。 查看以下方法
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
}
上述方法的$path
变量将能够返回所需的格式化资源。 例如, “ hunkeyPunkey / munkeyDunkeyChunkey”将输出为
/hunkey.punkey/munkey.dunkey.chunkey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.