Permalink
Browse files

Cleaner URL for paginatorHelper

Avoid appending &sort and &direction if the sort parameters are the one from options
  • Loading branch information...
1 parent 7fda8c7 commit 673638a36221627943346bf14909e0f50d18daab @Grafikart Grafikart committed Jan 31, 2014
Showing with 11 additions and 0 deletions.
  1. +8 −0 src/Controller/Component/PaginatorComponent.php
  2. +3 −0 src/View/Helper/PaginatorHelper.php
@@ -185,6 +185,12 @@ public function paginate($object, array $settings = []) {
$order = (array)$order;
}
reset($order);
+ $sortDefault = $directionDefault = false;
+ if (isset($defaults['order']) && count($defaults['order']) && count($defaults['order']) == 1){
+ $sortDefault = key($defaults['order']);
+ $directionDefault = current($defaults['order']);
+ }
+
$paging = array(
'findType' => $type,
'page' => $page,
@@ -196,6 +202,8 @@ public function paginate($object, array $settings = []) {
'sort' => key($order),
'direction' => current($order),
'limit' => $defaults['limit'] != $options['limit'] ? $options['limit'] : null,
+ 'sortDefault' => $sortDefault,
+ 'directionDefault' => $directionDefault
);
if (!isset($request['paging'])) {
@@ -440,6 +440,9 @@ public function url($options = array(), $model = null) {
if (!empty($url['page']) && $url['page'] == 1) {
$url['page'] = null;
}
+ if (isset($paging['sortDefault']) && isset($paging['directionDefault']) && $url['sort'] == $paging['sortDefault'] && $url['direction'] == $paging['directionDefault'] ) {
+ $url['sort'] = $url['direction'] = null;
+ }
return parent::url($url);
}

0 comments on commit 673638a

Please sign in to comment.