Saturday, March 21, 2015

CakePHP 2.6.X Pagination Sort Errors

I am faced a new issues regarding CakePHP 2.6.X and pagination; I've never had this issue before and it only happens when attempting to use $this->Paginator->sort(...) in a view.

$this->Paginator->sort('Page.id', 'ID', array('model' => 'Page'));

$this
->Paginator->sort('Page.id', 'ID');

$this
->Paginator->sort('id');

I've done the normal setup of the pagination object in the controller

$this->Paginator->settings = array(
    'contain' => false,
    'group' => 'Page.id',
    'order' => 'Page.name ASC',
    'limit' => 20
);

$results
= $this->Paginator->paginate('Page');

I am getting this in the view file

Warning (2): array_filter() expects parameter 1 to be array, null given [CORE/Cake/View/Helper/PaginatorHelper.php, line 435]

Warning (2): array_merge() [function.array-merge]: Argument #1 is not an array [CORE/Cake/View/Helper/PaginatorHelper.php, line 435]

Upon tracking the issue it stems from the params function on line 126 in the pagination helper, on line 131 it is returning null because request->params['paging'] is null.

if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) { return null; }

With the above explained, why is request->params['paging'] null? Shouldn't it be populated with information as it is in other sections? Is the sort function broken or am I missing something? Any help would be greatly appreciated.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: