Guys,
I have a code which showing data from 3 tables in a page
but, what I want is a single table can use a query limit
this is my code
$features = $this->paginate($this->Features);
$categories = $this->paginate($this->Categories);
$articles = $this->paginate($this->Articles->find('all', [
'limit' => 1,
'order' => 'Articles.created DESC',
]));
$this->set(compact('articles'));
$this->set(compact('categories'));
$this->set(compact('features'));
but it did not working, all data still showing
You have the array with your pagination specs inside the find call rather than as a param on the paginate call. Should be:
$articles = $this->paginate(
$this->Articles->find('all'),
[
'limit' => 1,
'order' => 'Articles.created DESC',
]
);
Thank you for your respond, but this code is error in my controller
showing error:
$sortDefault = key($defaults[‘order’]);
in directory vendor\cakephp\cakephp\src\Datasource\Paginator.php
Zuluru
January 27, 2020, 3:39pm
4
That’s not an error message, that’s a bit of code. What error does it give you?
The ‘order’ option in the Pagination component has a slightly different syntax as illustrated in the book
try:
$articles = $this->paginate(
$this->Articles->find('all'),
[
'limit' => 1,
'order' => [
'Articles.created' => 'desc'
]
]
);