diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index f5e197a0558..8dd83a144c2 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/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'; diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 6939f00b5aa..69095f1d89a 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/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); + } } -?> +?> \ No newline at end of file