fix Paginator::numbers() seperator: #2685

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5360 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-06-27 15:53:38 +00:00
parent 642b45a008
commit c405d3ad6b
2 changed files with 12 additions and 16 deletions

View file

@ -432,7 +432,7 @@ class PaginatorHelper extends AppHelper {
), ),
$options); $options);
$params = $this->params($options['model']); $params = am(array('page'=> 1), $this->params($options['model']));
unset($options['model']); unset($options['model']);
if ($params['pageCount'] <= 1) { if ($params['pageCount'] <= 1) {
@ -458,29 +458,25 @@ class PaginatorHelper extends AppHelper {
$end = $params['pageCount']; $end = $params['pageCount'];
} }
$start = $params['page'] - ($modulus - ($end - $params['page'])); $start = $params['page'] - ($modulus - ($end - $params['page']));
if ($start <= 1) { if ($start <= 1) {
$start = 1; $start = 1;
$end = $params['page'] + ($modulus - $params['page']) + 1; $end = $params['page'] + ($modulus - $params['page']) + 1;
} }
for ($i = $start; $i < $params['page']; $i++) { for ($i = $start; $i < $params['page']; $i++) {
$out .= $this->link($i, am($options['url'], array('page' => $i)), $options); $out .= $this->link($i, am($options['url'], array('page' => $i)), $options) . $separator;
$out .= $separator;
} }
$out .= $params['page']; $out .= $params['page'] . $separator;
$out .= $separator;
$start = $params['page'] + 1; $start = $params['page'] + 1;
for ($i = $start; $i < $end; $i++) {
for ($i = $start; $i <= $end; $i++) { $out .= $this->link($i, am($options['url'], array('page' => $i)), $options) . $separator;
$out .= $this->link($i, am($options['url'], array('page' => $i)), $options);
$out .= $separator;
} }
$out .= $this->link($i, am($options['url'], array('page' => $end)), $options);
} else { } else {
for ($i = 1; $i < $params['pageCount']; $i++) { for ($i = 1; $i < $params['pageCount']; $i++) {
if (isset($params['page']) && $i == $params['page']) { if ($i == $params['page']) {
$out .= $i . $separator; $out .= $i . $separator;
} else { } else {
$out .= $this->link($i, am($options['url'], array('page' => $i)), $options) . $separator; $out .= $this->link($i, am($options['url'], array('page' => $i)), $options) . $separator;

View file

@ -98,8 +98,8 @@ class PaginatorTest extends UnitTestCase {
$result = $this->paginator->sort('date'); $result = $this->paginator->sort('date');
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc"\s*>Date<\/a>$/', $result); $this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:date\/direction:desc"\s*>Date<\/a>$/', $result);
$result = $this->paginator->numbers(array('url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list')); $result = $this->paginator->numbers(array('modulus'=> '2', 'url'=> array('controller'=>'projects', 'action'=>'sort'),'update'=>'list'));
$this->assertPattern('/\/projects\/sort\/page:1/', $result); $this->assertPattern('/\/projects\/sort\/page:2/', $result);
$this->assertPattern('/<script type="text\/javascript">Event.observe/', $result); $this->assertPattern('/<script type="text\/javascript">Event.observe/', $result);
} }