CakePHP3: how to get result set size?


I have the following code:

$sites = $this->Sites->find()
		'postcode LIKE' => $this->request->data['numero'] . '%'
->sortBy(function($row) { return substr($row->postcode, 0, 2); }, SORT_ASC);

debug($sites); displays:

object(Cake\Collection\Iterator\SortIterator) {

'count' => (int) 428


And so I’m very desappointed because I don’t understand how to access to that count var.

I usuallly just do something like this:

$result = $connection->execute('SELECT COUNT(dogid) as total FROM dogs WHERE adopted = 0')->fetchAll('assoc');
$dogrows = $result[0]['total'];

That is just the count not the query that retrieves the results. You can use querybuilder also.

Should be $sites->count()

@rrd, unfortunately not, I tried it and I get the following error:

Error: You cannot issue a count on a Collection.