I have custom rest source, and in cakephp 3.5.* while testings, I use “little hack” to pass params to paginatoin helper, like:
$this->request->params['paging']['Posts'] = [
'finder' => 'all',
'page' => $page,
'current' => $solr['rows'] * $page,
'count' => $json['response']['numFound'],
'perPage' => $solr['rows'],
'prevPage' => $page > 1 ? true : false,
'nextPage' => $page < $pageCount ? true : false,
'pageCount' => $pageCount,
'sort' => null,
'direction' => false,
'limit' => null,
'sortDefault' => false,
'directionDefault' => false,
'scope' => null
];
But after upgrade to 3.6 this no more work when try to fix depractited code.
Accessing "params" as a property will be removed in 4.0.0. Use request->getParam() instead.
Any idea?
Hello,
Probably not the best way to do it, but a working one, I am using “action scoped” session.
I store the params sent in the session in a array like this one :
[
'custFilters' => [
'action1' => [
'action1_param1' = 'value1',
'action1_param2' = 'value2'
],
'action2' => [
'action2_param1' = 'value3',
'action2_param2' = 'value4'
]
]
];
Etc.
The behavior is that when you go back to the page, de filters are peristent.
Hope it can help you.
Regards
Salines
November 8, 2018, 11:51am
3
Here is solution: CakePHP 3.6 <
https://api.cakephp.org/3.5/class-Cake.Http.ServerRequest.html#_addParams
example in your controller:
$pagingOptions = [
'page' => $page,
'current' => $solr['rows'] * $page,
'count' => $total,
'perPage' => $solr['rows'],
'prevPage' => $page > 1 ? true : false,
'nextPage' => $page < $pageCount ? true : false,
'pageCount' => $pageCount,
'sort' => null,
'direction' => $this->request->getQuery('direction') ? mb_strtolower((string) $this->request->getQuery('direction')) : null,
'limit' => $this->request->getQuery('limit'),
'sortDefault' => false,
'directionDefault' => false,
'scope' => null
];
$this->request->addParams(['paging' => ['Postings' => $pagingOptions]]);
Salines
November 8, 2018, 12:31pm
4
The function Cake\Http\ServerRequest::addParams()
has been deprecated : 3.6.0 ServerRequest::addParams() is deprecated. Use withParam()
or withAttribute('params')
instead.
How to use code above with withParam()
or withAttribute('params')
?
$this->request = $this->request->withParam('paging', ['Postings' => $pagingOptions]);