如何在Apigility中获取资源名称?
我试过了
$route = $event->getRouteMatch();
但如果资源名称包含的名称多于名称,则将其拆分。
此外,我需要获取请求类型以区分get in" fetch&&取得所有"
答案 0 :(得分:0)
关于这一点:“我还需要获取请求类型以区分get in”fetch&&获取所有“
对于fetch all,with condition,你可以覆盖所有方法
$client = new \Zend\Http\Client($uri);
$client->setMethod('GET');
$client->setParameterGet(['id'=>1]);
//Or
$client->setParameterGet([]);
用于获取一个或获取方法
在网址后添加ID:
$uri.'/'.$id;
答案 1 :(得分:0)
您可以使用onBootstratp()
的{{1}}方法来捕捉它们。请查看以下方法
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
}
变量将能够返回您想要的格式化资源。例如,&#34; hunkeyPunkey / munkeyDunkeyChunkey&#34; 将输出为
$path