Order by in find() cakephp -
table unit(id, unitno, summary).
id | unitno
1 | 23
2 | 25
3 | 22
in 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 loop through our $posts array, printing out post info --> <?php foreach ($units $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>
i want use order unitno result still ordering id. http://s1104.photobucket.com/user/thai92hp/media/untitled.png.html
can me fix problem?
please give try:
public function index() { $this->set('units', $this->unit->find('all', array( 'order' => array('unit.unitno asc'), 'fields' => array('unit.id', 'unit.unitno') ) )); }
it seems me you've given order settings $this->set()
third parameter may want give $this->unit->find()
second parameter.
Comments
Post a Comment