Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaner URL for paginatorHelper

Avoid appending &sort and &direction if the sort parameters are the one from options
  • Loading branch information...
commit 673638a36221627943346bf14909e0f50d18daab 1 parent 7fda8c7
@Grafikart Grafikart authored
View
8 src/Controller/Component/PaginatorComponent.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'])) {
View
3  src/View/Helper/PaginatorHelper.php
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.