[英]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.