Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes #6473, dot notation for sort in next/prev

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8213 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 9e143bc3351d4cf03328e7446bdd9bfa8d517ef4 1 parent 92b8e87
gwoo authored
View
13 cake/libs/view/helpers/paginator.php
@@ -140,7 +140,9 @@ function sortKey($model = null, $options = array()) {
if (isset($options['sort']) && !empty($options['sort'])) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['sort'], $result) && isset($result[1])) {
- return $result[1];
+ if ($result[0] == $this->defaultModel()) {
+ return $result[1];
+ }
}
return $options['sort'];
} elseif (isset($options['order']) && is_array($options['order'])) {
@@ -149,6 +151,7 @@ function sortKey($model = null, $options = array()) {
if (preg_match('/(?:\w+\.)?(\w+)/', $options['order'], $result) && isset($result[1])) {
return $result[1];
}
+ return $options['order'];
}
return null;
}
@@ -223,13 +226,7 @@ function sort($title, $key = null, $options = array()) {
}
$dir = 'asc';
$sortKey = $this->sortKey($options['model']);
- $defaultModel = $this->defaultModel();
-
- if (strpos($sortKey, $defaultModel) !== false && strpos($key, $defaultModel) === false) {
- $isSorted = ($sortKey === $defaultModel . '.' . $key);
- } else {
- $isSorted = ($sortKey === $key);
- }
+ $isSorted = ($sortKey === $key);
if ($isSorted && $this->sortDir($options['model']) === 'asc') {
$dir = 'desc';
View
30 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -911,5 +911,33 @@ function testWithPlugin() {
$result = $this->Paginator->link('Page 3', array('page' => 3));
$this->assertPattern('/["\']\/issues\/index\/page:3["\']/', $result);
}
+
+/**
+ * testNextLinkUsingDotNotation method
+ *
+ * @access public
+ * @return void
+ */
+ function testNextLinkUsingDotNotation() {
+ Router::reload();
+ Router::parse('/');
+ Router::setRequestInfo(array(
+ array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
+ array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())
+ ));
+
+ $this->Paginator->params['paging']['Article']['options']['order'] = array('Article.title' => 'asc');
+ $this->Paginator->params['paging']['Article']['page'] = 1;
+
+ $test = array('url'=> array(
+ 'page'=> '1',
+ 'sort'=>'Article.title',
+ 'direction'=>'asc',
+ ));
+ $this->Paginator->options($test);
+
+ $result = $this->Paginator->next('Next');
+ $this->assertPattern('/\/accounts\/index\/page:2\/sort:Article.title\/direction:asc">Next<\/a>$/', $result);
+ }
}
-?>
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.