这是默认 Sylius 资源解析器中的一个错误,当您未分页或未limit
设置时,它会忽略标准和排序。要解决此问题,您应该覆盖sylius.resource_controller.resources_resolver.class
参数并为该getResources
方法使用以下实现:
public function getResources(RequestConfiguration $requestConfiguration, RepositoryInterface $repository)
{
if (null !== $repositoryMethod = $requestConfiguration->getRepositoryMethod()) {
$callable = [$repository, $repositoryMethod];
$resources = call_user_func_array($callable, $requestConfiguration->getRepositoryArguments());
return $resources;
}
// this has changed!
if (!$requestConfiguration->isPaginated() && !$requestConfiguration->isLimited()) {
return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit());
}
if (!$requestConfiguration->isPaginated()) {
return $repository->findBy($requestConfiguration->getCriteria(), $requestConfiguration->getSorting(), $requestConfiguration->getLimit());
}
return $repository->createPaginator($requestConfiguration->getCriteria(), $requestConfiguration->getSorting());
}