Hi,
I have a list of ordered items, ordered according to the int field order
.
I'm creating a gallery in CakePHP 1.2 that has a prev and next button and those should link to the previous and next item according to their ordering, not according to their id
.
In order to get this result I've included the 'order' parameter to the find function, and populated it with 'Item.order'=>'DESC'
. Still the result is an id
ordered list.
My question is: what do I do wrong? My controller:
$this->Item->id = 16;
$neighbours = $this->Item->find('neighbors', array('order'=>array('Item.order'=>'DESC'), 'fields'=>array('id','name')));
Solution I've tried a different approach. My code now does the job and looks as follows:
$order = $this->Item->findById(6);
$neighbours = $this->Item->find('neighbors', array('field'=>'order', 'value'=>$order['Item']['order']));
By setting the parameter 'field'
to the field will be the ordering field, and set the 'value'
parameter to the order value of you current Item you'll get the prev
and next
.