【发布时间】:2020-07-20 14:17:36
【问题描述】:
我喜欢为 APiPlatform 资源生成 uri,这对我来说似乎很初级,但我似乎不知道怎么做。这就是我想要完成的:
鉴于下面的资源定义,我想根据资源类名称、操作类型和操作名称获取 url。
/**
* @ApiResource(
* itemOperations={"GET"},
* collectionOperations={"GET"}
* )
*/
class Customer
{
// ...
}
$path = $someApiPlatformService->getOperationPath(Customer::class, ApiPlatform\Core\Api\OperationType::COLLECTION, 'GET');
路径的预期值为/api/customers。
$itemId = 'someid';
$path = $someApiPlatformService->getOperationPath(Customer::class, ApiPlatform\Core\Api\OperationType::ITEM, 'GET', $itemId);
路径的预期值为/api/customers/someid。
【问题讨论】:
标签: php symfony api-platform.com