可以在每个实体类的注解中使用path
或collectionOperations
和itemOperations
属性来设置单独的路由,这样就可以使用api_platform.prefix
了。
例如:
use ApiPlatform\Core\Annotation\ApiResource;
/**
* @ApiResource(
* attributes={
* "order"={"name": "ASC"},
* "pagination_enabled"=false
* },
* collectionOperations={"get"={"path"="/custom/path"}},
* itemOperations={"get"={"path"="/custom/path/{id}"}}
* )
*/
class MyEntity
{
// ...
}
这里的path
属性可以指定实体文档的自定义路径,而不使用默认的路由。这样在生成API文档时,就可以使用api_platform.prefix
来设置API的前缀。