custom order by in cakephp

Solutions on MaxInterview for custom order by in cakephp by the best coders in the world

showing results for - "custom order by in cakephp"
Cierra
19 Jan 2019
1// In mysql you can order by specific field values, by using ORDER BY FIELD:
2SELECT * FROM city 
3WHERE id IN (10, 1, 2)
4ORDER BY FIELD(id, 10, 1, 2) DESC;
5
6// output:
7// order: first those with id = 10, those with id = 1, those with id = 2
8// Do in cake
9	'order' => array(
10		'FIELD(City.id, 10, 1, 2)',
11	),
12
13// or
14    'order' => array(
15		'FIELD(City.id, 10, 1, 2) DESC',
16	),
17
18
19