我需要按日期排序一些数据,但不知怎的,我无法使其正常工作
这可能是因为我使用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'
)
) )