Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Standardizing format string in PaginatorHelper::counter(), %page% bec…

…omes {:page}, old keys still work, but will be deprecated
  • Loading branch information...
commit c2f111a45a2855d894d5748b576535adb2372df8 1 parent 2317420
@nateabele nateabele authored
View
31 cake/libs/view/helpers/paginator.php
@@ -390,6 +390,7 @@ function defaultModel() {
* Returns a counter string for the paged result set
*
* @param mixed $options Options for the counter string. See #options for list of keys.
+ * @todo See about deprecating the keys in $map for formatting
* @return string Counter string.
*/
function counter($options = array()) {
@@ -429,7 +430,7 @@ function counter($options = array()) {
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
break;
default:
- $replace = array(
+ $map = array(
'%page%' => $paging['page'],
'%pages%' => $paging['pageCount'],
'%current%' => $paging['current'],
@@ -437,7 +438,12 @@ function counter($options = array()) {
'%start%' => $start,
'%end%' => $end
);
- $out = str_replace(array_keys($replace), array_values($replace), $options['format']);
+ $out = str_replace(array_keys($map), array_values($map), $options['format']);
+
+ $newKeys = array(
+ '{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}'
+ );
+ $out = str_replace($newKeys, array_values($map), $out);
break;
}
return $this->output($out);
@@ -452,22 +458,17 @@ function counter($options = array()) {
function numbers($options = array()) {
if ($options === true) {
$options = array(
- 'before' => ' | ', 'after' => ' | ',
- 'first' => 'first', 'last' => 'last',
- );
+ 'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
+ );
}
- $options = array_merge(
- array(
- 'tag' => 'span',
- 'before'=> null, 'after'=> null,
- 'model' => $this->defaultModel(),
- 'modulus' => '8', 'separator' => ' | ',
- 'first' => null, 'last' => null,
- ),
- (array)$options);
+ $defaults = array(
+ 'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(),
+ 'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null,
+ );
+ $options += $defaults;
- $params = array_merge(array('page'=> 1), (array)$this->params($options['model']));
+ $params = (array)$this->params($options['model']) + array('page'=> 1);
unset($options['model']);
if ($params['pageCount'] <= 1) {
View
11 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -739,9 +739,16 @@ function testCounter() {
),
)
);
- $input = 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%';
+ $input = 'Page %page% of %pages%, showing %current% records out of %count% total, ';
+ $input .= 'starting on record %start%, ending on %end%';
+ $result = $this->Paginator->counter($input);
+ $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ';
+ $expected .= 'ending on 3';
+ $this->assertEqual($result, $expected);
+
+ $input = 'Page {:page} of {:pages}, showing {:current} records out of {:count} total, ';
+ $input .= 'starting on record {:start}, ending on {:end}';
$result = $this->Paginator->counter($input);
- $expected = 'Page 1 of 5, showing 3 records out of 13 total, starting on record 1, ending on 3';
$this->assertEqual($result, $expected);
$input = 'Page %page% of %pages%';
Please sign in to comment.
Something went wrong with that request. Please try again.