CakePHP无法使用MAX(日期)和分页按日期排序

时间:2015-05-27 09:57:14

标签: php cakephp pagination

我需要按日期排序一些数据,但不知怎的,我无法使其正常工作 这可能是因为我使用MAX(UserConnexion.date) as date但我无法弄清楚如何解决这个问题。

我正在使用它来分页:

Controlleur.php

$this->UserConnexion->virtualFields['count'] = 'COUNT(UserConnexion.email)';
$order = "UserConnexion.count";

$paginate=array(
    'fields'=>array('COUNT(UserConnexion.email) as count, 
                     email, 
                     MAX(UserConnexion.date) as date'),
    'group'=>array('UserConnexion.email'),
    'order'=>array($order => 'DESC')
);

$this->Paginator->settings = $paginate;

View.ctp

<th><?php echo $this->Paginator->sort('date', 'Last connexion'); ?></th>

分页的输出如下:

array(    
    (int) 0 => array(     
        (int) 0 => array(    
            'count' => '67',     
            'date' => '2015-05-15 10:09:43'   
        ),      
        'AgentsAppUserconnect' => array(      
            'email' => 'hugo@email.fr'     
        )   
    ),      
    (int) 1 => array(        
        (int) 0 => array(      
            'count' => '1',        
            'date' => '2015-04-27 15:27:52'      
        ),          
        'AgentsAppUserconnect' => array(        
            'email' => 'ludo@email.fr'      
        )     
    )        )

0 个答案:

没有答案