How to paginate associated records?

The paginator doesn’t support paginating associations, you’ll have to read the associated records manually in a separate query, and paginate that one, something along the lines of this: $product = $this->Products ->findBySlug($slug_prod) ->contain([‘Metas’, ‘Attachments’]) ->first(); $categoriesQuery = $this->Products->Categories ->find() ->innerJoinWith(‘Products’, function (\Cake\ORM\Query $query) use ($product) { return $query->where([ ‘Products.id’ => $product->id, ]); }) ->group(‘Categories.id’); $paginationOptions … Read more

How to output custom HTTP body contents with CakePHP 3.4? Echoing causes “Unable to emit headers” error

Controllers should never echo data! Echoing data can lead to all kinds of problems, from the data not being recognized in the test environment, to headers not being able to be sent, and even data being cut off. Doing it that way was already wrong in CakePHP 2.x, even though it might have worked in … Read more