在使用 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 是否可以进行结果排序(如果可以,我错在哪里)?或者我应该在我的控制器中手动处理它?