Apigility 获取资源名称和请求方法类型

Apigility get Resource name and request method type

如何在 Apigility 中获取资源名称? 我试过了
$route = $event->getRouteMatch(); 但如果资源名称包含多个名称,则将其拆分为 .

例如,如果 reouece 名称为“employeeVerifySomething”,它 return “employee.verify.something” ?

我还需要获取请求类型以区分“获取 && 获取所有”

要点:"Also i need to get request type to distinguish between get in "fetch && fetch all "

fetch all,with condition,可以重写fetch all方法

$client = new \Zend\Http\Client($uri);
            $client->setMethod('GET');
            $client->setParameterGet(['id'=>1]);

       //Or
        $client->setParameterGet([]);

获取一个或获取方法

在url之后添加id:

        $uri.'/'.$id;

您可以在 module.config.phponBootstratp() 方法中捕捉它们。看看下面的方法

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变量就可以return你想要的格式化资源。例如,"hunkeyPunkey/munkeyDunkeyChunkey" 将输出为

/hunkey.punkey/munkey.dunkey.chunkey