Hi i want to sort a dropdown list by its second value(not the id) i tried using order in the find but it doesn’t work. Im using cakephp 2.x
I would expect you to be able to sort your query.
But if you continue to have a problem there you could resort to php’s sort() https://www.php.net/manual/en/function.sort
Show us the code you’re using.
$codetravails = $this->Codetravail->find(‘list’, array(
‘conditions’ => array(‘client_id’ => array($this->request->data[‘client_id’], 0)),
‘fields’ => array(‘id’, ‘description’),
‘order’ => array(‘description’ => ‘ASC’)
));
Looks like it should work, but I skipped from 1.3 straight to 3.x, so I can’t say for sure. Hopefully someone else will be able to confirm whether order
is supposed to work with list
queries.
I can’t run a test (no 2x install) but that does look ok. There is no explicit example of the use of order
in a 'list` find. But it’s reasonable to expect to work.
There is an alternative syntax you could try
$codetravails = $this->Codetravail->find(‘list’, array(
‘conditions’ => array(‘client_id’ => array($this->request->data[‘client_id’], 0)),
‘fields’ => array(‘id’, ‘description’),
‘order’ => array(‘description ASC’) //just value, not key=>value
));