cake/libs/view/helpers/paginator.php
/**
 * Returns a counter string for the paged result set
 *
 * Options
 *
 * - `model` The model to use, defaults to PaginatorHelper::defaultModel();
 * - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
 *    set to 'range' to generate output like '1 - 3 of 13'.  Can also be set to a custom string, containing 
 *    the following placeholders `%page%`, `%pages%`, `%current%`, `%count%`, `%start%`, `%end%` and any
 *    custom content you would like.
 * - `separator` The separator string to use, default to ' of '
 *
 * @param mixed $options Options for the counter string. See #options for list of keys.
 * @return string Counter string.
 */
Returns a counter string for the paged result set
Options



@param mixed $options Options for the counter string. See #options for list of keys.
@return string Counter string.
Returns a counter string for the paged result set Options @param mixed $options Options for the counter string . See #options for list of keys . @return string Counter string .
function counter($options = array()) {
		if (is_string($options)) {
			$options = array('format' => $options);
		}
		$options = array_merge(
			array(
				'model' => $this->defaultModel(),
				'format' => 'pages',
				'separator' => __(' of ', true)
			),
		$options);
		$paging = $this->params($options['model']);
		if ($paging['pageCount'] == 0) {
			$paging['pageCount'] = 1;
		}
		$start = 0;
		if ($paging['count'] >= 1) {
			$start = (($paging['page'] - 1) * $paging['options']['limit']) + 1;
		}
		$end = $start + $paging['options']['limit'] - 1;
		if ($paging['count'] < $end) {
			$end = $paging['count'];
		}
		switch ($options['format']) {
			case 'range':
				if (!is_array($options['separator'])) {
					$options['separator'] = array(' - ', $options['separator']);
				}
				$out = $start . $options['separator'][0] . $end . $options['separator'][1] . $paging['count'];
			break;
			case 'pages':
				$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
			break;
			default:
				$replace = array(
					'%page%' => $paging['page'],
					'%pages%' => $paging['pageCount'],
					'%current%' => $paging['current'],
					'%count%' => $paging['count'],
					'%start%' => $start,
					'%end%' => $end
				);
				$out = str_replace(array_keys($replace), array_values($replace), $options['format']);
			break;
		}
		return $this->output($out);
	}
function counter ( $ options = array ( ) ) { if ( is_string ( $ options ) ) { $ options = array ( 'format' => $ options ) ; } $ options = array_merge ( array ( 'model' => $ this -> defaultModel ( ) , 'format' => 'pages' , 'separator' => __ ( ' of ' , true ) ) , $ options ) ; $ paging = $ this -> params ( $ options [ 'model' ] ) ; if ( $ paging [ 'pageCount' ] == 0 ) { $ paging [ 'pageCount' ] = 1 ; } $ start = 0 ; if ( $ paging [ 'count' ] >= 1 ) { $ start = ( ( $ paging [ 'page' ] - 1 ) * $ paging [ 'options' ] [ 'limit' ] ) + 1 ; } $ end = $ start + $ paging [ 'options' ] [ 'limit' ] - 1 ; if ( $ paging [ 'count' ] < $ end ) { $ end = $ paging [ 'count' ] ; } switch ( $ options [ 'format' ] ) { case 'range' : if ( ! is_array ( $ options [ 'separator' ] ) ) { $ options [ 'separator' ] = array ( ' - ' , $ options [ 'separator' ] ) ; } $ out = $ start . $ options [ 'separator' ] [ 0 ] . $ end . $ options [ 'separator' ] [ 1 ] . $ paging [ 'count' ] ; break ; case 'pages' : $ out = $ paging [ 'page' ] . $ options [ 'separator' ] . $ paging [ 'pageCount' ] ; break ; default : $ replace = array ( '%page%' => $ paging [ 'page' ] , '%pages%' => $ paging [ 'pageCount' ] , '%current%' => $ paging [ 'current' ] , '%count%' => $ paging [ 'count' ] , '%start%' => $ start , '%end%' => $ end ) ; $ out = str_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ options [ 'format' ] ) ; break ; } return $ this -> output ( $ out ) ; }
Returns a counter string for the paged result set
 Options
Returns a counter string for the paged result set Options