尝试使用KNP分页器设置自定义过滤器。遵循此Option Explicit
我有以下查询:
http://localhost:8000/items?sort=created_at&direction=asc&page=1
和我的分页器代码:
$em = $this->getDoctrine()->getManager();
$query = $em->getRepository(Item::class)->paginateQuery($options);
$paginator = $this->get('knp_paginator');
$items = $paginator->paginate (
$query,
$request->query->getInt('page', 1),
9,
array(
'pageParameterName' => 'page',
'sortFieldParameterName' => 'sort',
'sortDirectionParameterName' => 'direction'
)
);`
但我收到此错误消息:
message There is no component field [created_at] in the given Query
class UnexpectedValueException
为什么在名称后加上方括号?我一定想念一些大事
编辑:
如果仅出于此原因我更改为'sortFieldParameterName' => 'created_at',
,就没有更多错误消息!!!毫无意义,created_at
不是字段名,而是URL中的值