所以,如果我有一个使用历史数据库表,比如
id file email date_send
1 1.txt A 2013-01-31 15:26:00
2 2.txt A 2013-01-31 15:26:00
3 3.txt B 2013-01-30 12:26:00
我想在视图中显示它
Date email File
2013-01-31 15:26:00 A 1.txt
2.txt
2013-01-30 12:26:00 B 3.txt
考虑到 cakephp 中的分页,我该怎么做。我现在所拥有的几乎只是按原样展示
Date email File
2013-01-31 15:26:00 A 1.txt
2013-01-31 15:26:00 A 2.txt
2013-01-30 12:26:00 B 3.txt
我在控制器中的代码
$this->paginate = array(
'UsageHistory' => array(
'conditions' => array(
'UsageHistory.user_id' => $id
),
'order' => 'UsageHistory.date_send DESC'
)
);
$this->set('usageHistory', $this->paginate('UsageHistory'));
并且在视图中
<?php if ( !empty($usageHistory) ) { ?>
<?php foreach ( $usageHistory as $history ) :?>
<tr>
<td class="filename"><?php echo $history['UsageHistory']['file_name']; ?></td>
<td class="recip"><?php echo $history['UsageHistory']['recipient_email']; ?></td>
<td class="size"><?php echo round($history['UsageHistory']['file_size']/1048576*100)/100 . ' MB'; ?></td>
<td class="datesent"><?php echo $this->Time->format('m/d/o h:i A', $history['UsageHistory']['date_send']); ?></td>
</tr>
<?php endforeach; ?>
<?php } else { ?>
<tr>
<td colspan="3">No Usage History Yet</td>
</tr>
<?php } ?>