Merge pull request #448 from majna/2.1-paging-current

Add option for 'current' class to PaginationHelper::numbers().
This commit is contained in:
Mark Story 2012-01-28 10:06:56 -08:00
commit 21cf8ad018
2 changed files with 48 additions and 3 deletions

View file

@ -1298,6 +1298,50 @@ class PaginatorHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('first' => 1, 'currentClass' => 'active'));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'active')), '2', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link', 'currentClass' => 'active'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
' | ',
array('span' => array('class' => 'active page-link')), '2', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:3')), '3', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:4')), '4', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:5')), '5', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:6')), '6', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:7')), '7', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:8')), '8', '/a', '/span',
' | ',
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);
$result = $this->Paginator->numbers(array('last' => 1));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',

View file

@ -642,6 +642,8 @@ class PaginatorHelper extends AppHelper {
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
* links to generate.
* - `ellipsis` Ellipsis content, defaults to '...'
* - `class` Class for wrapper tag
* - `currentClass` Class for wrapper tag on current active page, defaults to 'current'
*
* @param mixed $options Options for the numbers, (before, after, model, modulus, separator)
* @return string numbers string.
@ -656,7 +658,7 @@ class PaginatorHelper extends AppHelper {
$defaults = array(
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...', 'currentClass' => 'current'
);
$options += $defaults;
@ -670,7 +672,7 @@ class PaginatorHelper extends AppHelper {
extract($options);
unset($options['tag'], $options['before'], $options['after'], $options['model'],
$options['modulus'], $options['separator'], $options['first'], $options['last'],
$options['ellipsis'], $options['class']
$options['ellipsis'], $options['class'], $options['currentClass']
);
$out = '';
@ -704,7 +706,6 @@ class PaginatorHelper extends AppHelper {
. $separator;
}
$currentClass = 'current';
if ($class) {
$currentClass .= ' ' . $class;
}