0

我的分页设置如下所示:

        $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。

谢谢。

4

1 回答 1

0

对于复杂的查询默认排序是行不通的,所以你应该创建一个视图并使用与模型相同的视图,你肯定会得到分页排序。通过使用视图,您的应用程序性能也会提高

于 2013-11-12T13:09:25.787 回答