我的分页设置如下所示:
$this->Paginator->settings = array(
'limit' => 100,
'order' => 'Traffic.accessed DESC',
'conditions' => array(
'Traffic.webmaster_site_id' => $this->WebmasterSite->find('list', array(
'fields' => 'WebmasterSite.id',
'conditions' => array(
'WebmasterSite.user_id' => $this->Auth->user('id')
)
))
),
'fields' => 'DATE(Traffic.accessed) AS `access_date`,
SUM(Traffic.webmaster_site_transfer) as total_webmaster_income,
COUNT(Traffic.webmaster_site_id) as total_webmaster_clicks',
'group' => 'DATE(Traffic.accessed)',
'paramType' => 'querystring'
);
$click_data = $this->Paginator->paginate('Traffic');
$this->set('click_data', $click_data);
并且在视图中
<th class="text-center">
<?php if ($this->Paginator->sortKey() == 'Traffic.total_webmaster_clicks') {
if ($this->Paginator->sortDir() == 'asc') {
$sort_icon = '<i class="icon-sort-up"></i> ';
} else {
$sort_icon = '<i class="icon-sort-down"></i> ';
}
} else {
$sort_icon = '<i class="icon-sort"></i> ';
} ?>
<?php echo $this->Paginator->sort('Traffic.total_webmaster_clicks',$sort_icon.__('Total Clicks'),array('escape'=>false)); ?>
</th>
所以按Traffic.total_webmaster_clicks
它不排序。请注意,这来自AS total_webmaster_clicks
分页语句。
我不明白如何对此类(选定的)字段和 GROUP BY 进行排序。另外我无法创建虚拟字段,因为 DATETIME 字段有一个 GROUP BY。
谢谢。