-1
表單元(id,unitNo,summary)。在find()中排序cakephp
id | unitNo
1 | 23
2 | 25
3 | 22
在UnitsController:
public function index() {
$this->set('units', $this->Unit->find('all'), array(
'order' => array('Unit.unitNo ASC'),
'fields' => array('Unit.id', 'Unit.unitNo'))
);
}
index.ctp
<table>
<tr>
<th>Unit</th>
<th>Summary</th>
</tr>
<!-- Here is where we loop through our $posts array, printing out post info -->
<?php foreach ($units as $unit): ?>
<tr>
<td>
<?php echo $this->Html->link($unit['Unit']['unitNo'], array('controller' => 'units', 'action' => 'view', $unit['Unit']['id']));
?>
</td>
<td><?php echo $unit['Unit']['summary']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($unit); ?>
</table>
我想使用順序unitNo但結果仍是按id訂購。 http://s1104.photobucket.com/user/thai92hp/media/Untitled.png.html
任何人都可以幫助我解決這個問題嗎?
哇!你是對的!非常感謝! <3 – 2014-12-02 06:32:25
很高興我能幫助,歡呼! – kyo 2014-12-02 06:43:43