Symfony 使用KnpPaginator进行排序
我在尝试使用KnpPaginator进行排序时遇到了一个问题。我遵循了许多链接,并在代码中尝试了大量迭代,但似乎无法正常工作。我丢失了一些东西,但找不到 目前唯一有效的是表格标题,我可以点击它,但除了刷新页面并在分页1时刷新我之外,什么都没有发生。 我在做symfony2.3 这是我的包配置Symfony 使用KnpPaginator进行排序,symfony,sorting,knppaginator,Symfony,Sorting,Knppaginator,我在尝试使用KnpPaginator进行排序时遇到了一个问题。我遵循了许多链接,并在代码中尝试了大量迭代,但似乎无法正常工作。我丢失了一些东西,但找不到 目前唯一有效的是表格标题,我可以点击它,但除了刷新页面并在分页1时刷新我之外,什么都没有发生。 我在做symfony2.3 这是我的包配置 knp_paginator: page_range: 5 # default page range used in pagination control defau
knp_paginator:
page_range: 5 # default page range used in pagination control
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
template:
pagination: 'KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig' # sliding pagination controls template
sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig' # sort link template
这是我的控制器,我在这里用getRepository设置了Knp
private function resultsAction(Request $request, User $user, $type, $archive)
{
$em = $this->getDoctrine()->getManager();
$query = $em->getRepository("STUserBundle:Operation")->getQueryByTypeAndPro($type, $user, $archive);
$paginator = $this->get('knp_paginator');
$results = $paginator->paginate(
$query,
$request->query->getInt('page',1),
$request->query->getInt('limit',50)
);
return array("results" => $results, "archive" => $archive);
}
public function offreAction(Request $request, User $user, $archive = false)
{
return $this->resultsAction($request, $user, Operation::OFFRE_COMMERCIALE, $archive);
}
这是我的回购协议,查询是在这里完成的:
public function getQueryByTypeAndPro($type, User $user, $archive)
{
return $this->createQueryBuilder("opn")
->andWhere("opn.type = :type")
->setParameter("type", $type)
->andWhere("opn.resellerId = :reseller")
->setParameter("reseller", $user->getId())
->andWhere("opn.archive = :archive")
->setParameter('archive', $archive)
->orderBy("opn.dateCreation", "DESC")
->getQuery()
;
}
这是我的观点,我试图使事情与Knp合作
<tr>
<th>{{ knp_pagination_sortable(results, 'general.vehicule.ref'|trans, 'opn.type') }}</th>
<th>{{ knp_pagination_sortable(results, 'general.vehicule.vehicule'|trans, 'opn.resellerId') }}</th>
<th>{{ knp_pagination_sortable(results, 'notifications.client'|trans, 'opn.??') }}</th>
<th>{{ knp_pagination_sortable(results, 'general.date'|trans, 'opn.??') }}</th>
<th>{{ knp_pagination_sortable(results, 'commerce.achat.encours.etat'|trans, 'opn.??') }}</th>
</tr>
在我的表格中,当我点击它时,刷新页面但不排序。我很难理解如何才能做到这一点
我放“opn.”的地方是因为我不知道在那个地方放什么,我似乎不理解这个问题
我希望最后一个注明日期的项目是第一个,但由于能够使用Knpremove->orderByopn.dateCreation对其进行排序,DESC.KnpPaginator具有特殊的侦听器和助行器,可以根据请求以正确的顺序修改查询,然后为您执行分页操作
配置可排序查看。
翻译查看。删除->orderByopn.dateCreation,DESC.KnpPaginator有特殊的侦听器和助行器,可以根据请求以正确的顺序修改查询,然后为您执行分页操作
配置可排序查看。
翻译看。好的,我成功地完成了这项工作,以下是我所做的 config.yml
knp_paginator:
page_range: 5 # default page range used in pagination control
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: false # ensure distinct results, useful when ORM queries are using GROUP BY statements
template:
pagination: 'KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig' # sliding pagination controls template
sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig' # sort link template
回购
控制器
private function resultsAction(Request $request, User $user, $type, $archive)
{
$em = $this->getDoctrine()->getManager();
$paginator = $this->get('knp_paginator');
$qb = $em->getRepository("STUserBundle:Operation")->getQueryByTypeAndPro($type, $user, $archive);
$results = $paginator->paginate(
$qb,
$request->query->get('page',1),
$request->query->get('limit',50),
[
'defaultSortFieldName' => 'opn.dateCreation',
'defaultSortDirection' => 'desc'
]
);
return array("results" => $results, "archive" => $archive);
}
和树枝
<tr>
<th{% if results.isSorted('opn.id') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.vehicule.ref'|trans, 'opn.id') }}</th>
<th{% if results.isSorted('opn.vehiculeMarque') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.vehicule.vehicule'|trans, 'opn.vehiculeMarque') }}</th>
{% if typeOffre is defined and typeOffre == 'devisWeb' %}<th>Financement</th>{% endif %}
<th{% if results.isSorted('opn.clientNom') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'notifications.client'|trans, 'opn.clientNom') }}</th>
<th{% if results.isSorted('opn.dateCreation') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.date'|trans, 'opn.dateCreation') }}</th>
<th>{{ 'commerce.achat.encours.etat'|trans }}</th>
<th class="sorting_disabled">{{ 'commerce.achat.action'|trans }}</th>
<th class="sorting_disabled">{{ 'commerce.vente.operation.basculer'|trans }}</th>
</tr>
这样就行了好吧,我成功地做到了,这就是我所做的 config.yml
knp_paginator:
page_range: 5 # default page range used in pagination control
default_options:
page_name: page # page query parameter name
sort_field_name: sort # sort field query parameter name
sort_direction_name: direction # sort direction query parameter name
distinct: false # ensure distinct results, useful when ORM queries are using GROUP BY statements
template:
pagination: 'KnpPaginatorBundle:Pagination:twitter_bootstrap_v3_pagination.html.twig' # sliding pagination controls template
sortable: 'KnpPaginatorBundle:Pagination:sortable_link.html.twig' # sort link template
回购
控制器
private function resultsAction(Request $request, User $user, $type, $archive)
{
$em = $this->getDoctrine()->getManager();
$paginator = $this->get('knp_paginator');
$qb = $em->getRepository("STUserBundle:Operation")->getQueryByTypeAndPro($type, $user, $archive);
$results = $paginator->paginate(
$qb,
$request->query->get('page',1),
$request->query->get('limit',50),
[
'defaultSortFieldName' => 'opn.dateCreation',
'defaultSortDirection' => 'desc'
]
);
return array("results" => $results, "archive" => $archive);
}
和树枝
<tr>
<th{% if results.isSorted('opn.id') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.vehicule.ref'|trans, 'opn.id') }}</th>
<th{% if results.isSorted('opn.vehiculeMarque') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.vehicule.vehicule'|trans, 'opn.vehiculeMarque') }}</th>
{% if typeOffre is defined and typeOffre == 'devisWeb' %}<th>Financement</th>{% endif %}
<th{% if results.isSorted('opn.clientNom') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'notifications.client'|trans, 'opn.clientNom') }}</th>
<th{% if results.isSorted('opn.dateCreation') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(results, 'general.date'|trans, 'opn.dateCreation') }}</th>
<th>{{ 'commerce.achat.encours.etat'|trans }}</th>
<th class="sorting_disabled">{{ 'commerce.achat.action'|trans }}</th>
<th class="sorting_disabled">{{ 'commerce.vente.operation.basculer'|trans }}</th>
</tr>
这样就行了谢谢你的澄清。我发现如何使翻译与您的链接工作。然而,删除->orderByopn.dateCreation,DESC并没有让这项工作将您的bundle配置放在这里,看看这篇文章希望能帮助您感谢您的帮助,但我想我有一个与这篇文章不同的问题。很抱歉,到目前为止我还不能真正理解该怎么做,我将尝试制作一篇新文章。我将捆绑包配置放在了我的原始文章中/我搜索了你的文章和其他文章,但我仍然无法让它看起来有效@t。Abdelmalekt感谢你的清晰。我发现如何使翻译与您的链接工作。然而,删除->orderByopn.dateCreation,DESC并没有让这项工作将您的bundle配置放在这里,看看这篇文章希望能帮助您感谢您的帮助,但我想我有一个与这篇文章不同的问题。很抱歉,到目前为止我还不能真正理解该怎么做,我将尝试制作一篇新的帖子。我将捆绑包配置放在了我的原始帖子中/我搜索了你的帖子和其他帖子,但我仍然无法让它看起来能正常工作@t.Abdelmalek