我的路线定义:
'router' => [
'routes' => [
'TimeTable' => [
'type' => 'Literal',
'options' => [
// Change this to something specific to your module
'route' => '/tt',
],
'may_terminate' => false,
'child_routes' => [
'API' => [
'type' => 'Literal',
'options' => [
// Change this to something specific to your module
'route' => '/api',
],
'may_terminate' => false,
'child_routes' => [
'lines' => [
'type' => 'Literal',
'options' => [
// Change this to something specific to your module
'route' => '/lines',
'defaults' => [
'controller' => Controller\LineRestApiController::class,
],
],
'may_terminate' => true,
],
],
],
],
],
],
数据数据地图定义:
MetadataMap::class => [
[
'__class__' => RouteBasedCollectionMetadata::class,
'collection_class' => LineCollection::class,
'collection_relation' => 'lines',
'route' => 'TimeTable/API/Lines',
],
]
生成结果:
{
"_total_items": 78,
"_page": 1,
"_page_count": 4,
"_links": {
"self": {
"href": "http://xxx.xxx.xx"
},
"next": {
"href": "http://xxx.xxx.xx"
},
"last": {
"href": "http://xxx.xxx.xx"
}
},
"_embedded": {
"lines": [.....] }}
所有链接都是用不完整的href生成的,只有域部分,路由部分被剥离..
预期的结果是这样的:
"href" : "http://xxx.xxx.xx/xxx/tt/api/lines....."
我做错了,我不知道从哪里开始..
谢谢大家给我一些想法
简化控制器代码:
$psr7request = Psr7ServerRequest::fromZend($this->getRequest());
$list = this->entityManager->getRepository(Line::class)->getValidLinesCollection();
$resource = $this->resourceGenerator->fromObject($list, $psr7request);
echo Psr7Response::toZend($this->responseFactory->createResponse($psr7request, $resource))->getBody();
exit;
PS:我没有使用完整的zend-expressive只是zend-framework ..