CakePHP: find neighbors, order "name" or "order",

I have a list of ordered items ordered according to int field order. I am creating a gallery in CakePHP 1.2 that has a previous and next button, and they should refer to the previous and next elements according to their order, and not according to them id.

To get this result, I included the "order" parameter in the search function and populated it 'Item.order'=>'DESC'. However, the result is an ordered list id.

My question is: what am I doing wrong? My controller:

$this->Item->id = 16;

$neighbours = $this->Item->find('neighbors', array('order'=>array('Item.order'=>'DESC'), 'fields'=>array('id','name')));

Solution I tried a different approach. My code now does the job and looks like this:

$order = $this->Item->findById(6);

$neighbours = $this->Item->find('neighbors', array('field'=>'order', 'value'=>$order['Item']['order']));

'field' , , 'value' , prev next.

+5
2

, , .

$neighbours = $this->Item->find('neighbors', array(
    'order' => 'order DESC',
    'fields' => array('id', 'name', 'order')
));

, Item. ( , .) , [Item.]order ""

, , SQL-, . "" , , , .

+4

. , ( ) .

:

'FIELD(TestQuestion.id, 3, 1, 5)';

, 2897 Model.php:

$query['order'] = $field . ' DESC';

, :

  • "exam_order" :

    $this->TestQuestion->virtualFields['examination_order'] = 'FIELD(TestQuestion.id, 3, 1, 5)';
    
    $this->TestQuestion->order = array(
        $this->TestQuestion->alias . '.examination_order'
    );
    
  • find neighbors '' 'exam_order', , , :

    $neighbors = $this->TestQuestion->find(
        'neighbors',
        array(
            'field' => 'examination_order',
            'value' => $testQuestion[$this->TestQuestion->alias]['examination_order'],
            'conditions' => $conditions
        )
    );
    
0

All Articles