Using CakePHP 2.3, I'm retrieving data using a paginator. So, say my models are Countries having many Cities, and in my CountryController I have...
$this->Paginator->settings = [
'fields' => [
'id'
'country_name'
],
'contain' => [
'City' => [
'id'
'city_name',
'conditions' => [
'population >' => 1000000;
]
]
]
];
...which gets me a list of all counties with each row containing a list of any populous cities.
In the view I am obviously able to iterate foreach ($cities as $city)
and echo $country['country_name']
etc. and also if I wish I can show a count of the contained cities by echoing count($country['City'])
.
Using the paginator I can sort the country results by passing back a field name in the query string, e.g. sort=country_name
, but how can I get the results to sort by the count of the contained cities?