在自定义存储库上具有ApiPlatform的分页器

时间:2019-11-22 18:55:06

标签: symfony doctrine symfony4 api-platform.com

我想在回复中加入_redirectspublic,所以我遵循了文档https://api-platform.com/docs/core/pagination/#custom-controller-action,但出现此错误 “控制器必须返回一个“ Symfony \ Component \ HttpFoundation \ Response”对象,但它返回的是ApiPlatform \ Core \ Bridge \ Doctrine \ Orm \ Paginator类型的对象。”

hydra:totalItems
hydra:view

1 个答案:

答案 0 :(得分:0)

解决了! 我忘记的是注释中的默认参数

/**
 * @Route(
 *     name="api_fake_action",
 *     path="/api/fake",
 *     defaults={
 *         "_api_resource_class"=FakeEntity::class,
 *         "_api_collection_operation_name"="post_publication"
 *     }
 * )
 */
public function __invoke(): Paginator
{
    return $this->termRelationshipsRepository->findAllProductsIdsByTerm_id(126);
}