The combination of Collection function (in my case 'filter') and paginate() causes a error. The simplified PHP code is below:
$rooms = $this->Rooms
->find('all')
->formatResults(function ($results) {
return $results->map(function ($row) {
//...
$row->free_booking=0;
if($someCondition) $row->free_booking=1;
//...
return $row;
});
})
->filter(function ($booking, $key) {
return $booking->free_booking == 1;
});
$this->set('rooms',$this->paginate($rooms));
The error is below:
Error: Call to undefined method ArrayIterator::alias() File .../public_html/vendor/cakephp/cakephp/src/Controller/Component/PaginatorComponent.php Line: 174
How to solve this problem?