【发布时间】:2012-09-17 17:27:25
【问题描述】:
在使用 Propel ORM 的 Symfony2 项目中,我尝试使用 KNP Paginator 包按列对列表视图进行排序。我的代码如下:
public function indexAction()
{
$query = CustomerQuery::create();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate($query, $this->get('request')->query->get('page', 1), 30);
return compact('pagination');
}
我的看法是:
<table>
<thead>
<tr>
<th>{{ pagination.sortable('Company', 'companyName')|raw }}</th>
<th>{{ pagination.sortable('Contact', 'contact')|raw }}</th>
<th>{{ pagination.sortable('E-mail', 'email')|raw }}</th>
</tr>
</thead>
<tbody>
{% for customer in pagination %}
<!-- [...] -->
{% endfor %}
</tbody>
</table>
生成的链接似乎是正确的,正如我得到的那样(例如):
/customers/?sort=companyName&direction=asc&page=1
但它不会对我的查询进行排序:在我生成的请求中没有 ORDER BY 子句。所以,我的问题是:Propel 是否可以进行结果排序(如果可以,我错在哪里)?还是应该在控制器中手动处理?
【问题讨论】: