Class PaginatorHelper

Pagination Helper class for easy generation of pagination links.

PaginationHelper encloses all methods needed when working with pagination.

Cake\View\Helper implements Cake\Event\EventListenerInterface uses Cake\Core\InstanceConfigTrait
Extended by Cake\View\Helper\PaginatorHelper uses Cake\View\StringTemplateTrait

Method Detail

__constructsource public

__construct( Cake\View\View $View , array $config [] )

Constructor. Overridden to merge passed args with URL options.

Parameters

Cake\View\View $View
The View this helper is being attached to.
array $config optional []
Configuration settings for the helper.

Overrides

Cake\View\Helper::__construct()

_firstNumbersource protected

_firstNumber( Cake\View\StringTemplate $ellipsis , array $params , integer $start , array $options )

Generates the first number for the paginator numbers() method.

Parameters

Cake\View\StringTemplate $ellipsis
StringTemplate instance.
array $params
Params from the numbers() method.
integer $start
Start number.
array $options
Options from the numbers() method.

Returns

string
Markup output.

_formatNumbersource protected

_formatNumber( Cake\View\StringTemplate $templater , array $options )

Formats a number for the paginator number output.

Parameters

Cake\View\StringTemplate $templater
StringTemplate instance.
array $options
Options from the numbers() method.

Returns

string
string

_getNumbersStartAndEndsource protected

_getNumbersStartAndEnd( array $params , array $options )

Calculates the start and end for the pagination numbers.

Parameters

array $params
Params from the numbers() method.
array $options
Options from the numbers() method.

Returns

array
An array with the start and end numbers.

_hasPagesource protected

_hasPage( string $model , integer $page )

Does $model have $page in its range?

Parameters

string $model
Model name to get parameters for.
integer $page
Page number you are checking.

Returns

boolean
Whether model has $page

_lastNumbersource protected

_lastNumber( Cake\View\StringTemplate $ellipsis , array $params , integer $end , array $options )

Generates the last number for the paginator numbers() method.

Parameters

Cake\View\StringTemplate $ellipsis
StringTemplate instance.
array $params
Params from the numbers() method.
integer $end
End number.
array $options
Options from the numbers() method.

Returns

string
Markup output.

_modulusNumberssource protected

_modulusNumbers( Cake\View\StringTemplate $templater , array $params , array $options )

Generates the numbers for the paginator numbers() method.

Parameters

Cake\View\StringTemplate $templater
StringTemplate instance.
array $params
Params from the numbers() method.
array $options
Options from the numbers() method.

Returns

string
Markup output.

_numberssource protected

_numbers( Cake\View\StringTemplate $templater , array $params , array $options )

Generates the numbers for the paginator numbers() method.

Parameters

Cake\View\StringTemplate $templater
StringTemplate instance.
array $params
Params from the numbers() method.
array $options
Options from the numbers() method.

Returns

string
Markup output.
_toggledLink( string|boolean $text , boolean $enabled , array $options , array $templates )

Generate an active/inactive link for next/prev methods.

Parameters

string|boolean $text
The enabled text for the link.
boolean $enabled
Whether or not the enabled/disabled version should be created.
array $options
An array of options from the calling method.
array $templates
An array of templates with the 'active' and 'disabled' keys.

Returns

string
Generated HTML

countersource public

counter( string|array $options [] )

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}}, {{model}}, {{start}}, {{end}} and any custom content you would like.

Parameters

string|array $options optional []
Options for the counter string. See #options for list of keys. If string it will be used as format.

Returns

string
Counter string.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter

currentsource public

current( string|null $model null )

Gets the current page of the recordset for the given model

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.

Returns

integer
The current page number of the recordset.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#checking-the-pagination-state

defaultModelsource public

defaultModel( )

Gets the default model of the paged sets

Returns

string|null
Model name or null if the pagination isn't initialized.

firstsource public

first( string|integer $first '<< first' , array $options [] )

Returns a first or set of numbers for the first pages.

echo $this->Paginator->first('< first');

Creates a single link for the first page. Will output nothing if you are on the first page.

echo $this->Paginator->first(3);

Will create links for the first 3 pages, once you get to the third or greater page. Prior to that nothing will be output.

Options:

  • model The model to use defaults to PaginatorHelper::defaultModel()
  • escape Whether or not to HTML escape the text.
  • url An array of additional URL options to use for link generation.

Parameters

string|integer $first optional '<< first'
if string use as label for the link. If numeric, the number of page links you want at the beginning of the range.
array $options optional []
An array of options.

Returns

string
numbers string.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-jump-links

generateUrlsource public

generateUrl( array $options [] , string|null $model null , boolean $full false )

Merges passed URL options with current pagination state to generate a pagination URL.

Parameters

array $options optional []
Pagination/URL options array
string|null $model optional null
Which model to paginate on
boolean $full optional false
If true, the full base URL will be prepended to the result

Returns

string
By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#generating-pagination-urls

hasNextsource public

hasNext( string|null $model null )

Returns true if the given result set is not at the last page

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.

Returns

boolean
True if the result set is not at the last page.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#checking-the-pagination-state

hasPagesource public

hasPage( string|null $model null , integer $page 1 )

Returns true if the given result set has the page number given by $page

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.
integer $page optional 1
The page number - if not set defaults to 1.

Returns

boolean
True if the given result set has the specified page number.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#checking-the-pagination-state

hasPrevsource public

hasPrev( string|null $model null )

Returns true if the given result set is not at the first page

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.

Returns

boolean
True if the result set is not at the first page.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#checking-the-pagination-state

implementedEventssource public

implementedEvents( )

Event listeners.

Returns

array
array

Overrides

Cake\View\Helper::implementedEvents()

lastsource public

last( string|integer $last 'last >>' , array $options [] )

Returns a last or set of numbers for the last pages.

echo $this->Paginator->last('last >');

Creates a single link for the last page. Will output nothing if you are on the last page.

echo $this->Paginator->last(3);

Will create links for the last 3 pages. Once you enter the page range, no output will be created.

Options:

  • model The model to use defaults to PaginatorHelper::defaultModel()
  • escape Whether or not to HTML escape the text.
  • url An array of additional URL options to use for link generation.

Parameters

string|integer $last optional 'last >>'
if string use as label for the link, if numeric print page numbers
array $options optional []
Array of options

Returns

string
numbers string.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-jump-links

metasource public

meta( array $options [] )

Returns the meta-links for a paginated result set.

echo $this->Paginator->meta();

Echos the links directly, will output nothing if there is neither a previous nor next page.

$this->Paginator->meta(['block' => true]);

Will append the output of the meta function to the named block - if true is passed the "meta" block is used.

Options:

  • model The model to use defaults to PaginatorHelper::defaultModel()
  • block The block name to append the output to, or false/absenst to return as a string

Parameters

array $options optional []
Array of options

Returns

string|null
Meta links

nextsource public

next( string $title 'Next >>' , array $options [] )

Generates a "next" link for a set of paged records

Options:

  • disabledTitle The text to used when the link is disabled. This defaults to the same text at the active link. Setting to false will cause this method to return ''.
  • escape Whether you want the contents html entity encoded, defaults to true
  • model The model to use, defaults to PaginatorHelper::defaultModel()
  • url An array of additional URL options to use for link generation.
  • templates An array of templates, or template file name containing the templates you'd like to use when generating the link for next page. The helper's original templates will be restored once next() is done.

Parameters

string $title optional 'Next >>'
Title for the link. Defaults to 'Next >>'.
array $options optional []
Options for pagination link. See above for list of keys.

Returns

string
A "next" link or $disabledTitle text if the link is disabled.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-jump-links

numberssource public

numbers( array $options [] )

Returns a set of numbers for the paged result set uses a modulus to decide how many numbers to show on each side of the current page (default: 8).

$this->Paginator->numbers(['first' => 2, 'last' => 2]);

Using the first and last options you can create links to the beginning and end of the page set.

Options

  • before Content to be inserted before the numbers, but after the first links.
  • after Content to be inserted after the numbers, but before the last links.
  • model Model to create numbers for, defaults to PaginatorHelper::defaultModel()
  • modulus How many numbers to include on either side of the current page, defaults to 8. Set to false to disable and to show all numbers.
  • first Whether you want first links generated, set to an integer to define the number of 'first' links to generate. If a string is set a link to the first page will be generated with the value as the title.
  • last Whether you want last links generated, set to an integer to define the number of 'last' links to generate. If a string is set a link to the last page will be generated with the value as the title.
  • templates An array of templates, or template file name containing the templates you'd like to use when generating the numbers. The helper's original templates will be restored once numbers() is done.
  • url An array of additional URL options to use for link generation.

The generated number links will include the 'ellipsis' template when the first and last options and the number of pages exceed the modulus. For example if you have 25 pages, and use the first/last options and a modulus of 8, ellipsis content will be inserted after the first and last link sets.

Parameters

array $options optional []
Options for the numbers.

Returns

string
numbers string.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-page-number-links

optionssource public

options( array $options [] )

Sets default options for all pagination links

Parameters

array $options optional []
Default options for pagination links. See PaginatorHelper::$options for list of keys.

paramsource public

param( string $key , string|null $model null )

Convenience access to any of the paginator params.

Parameters

string $key
Key of the paginator params array to retrieve.
string|null $model optional null
Optional model name. Uses the default if none is specified.

Returns

mixed
Content of the requested param.

paramssource public

params( string|null $model null )

Gets the current paging parameters from the resultset for the given model

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.

Returns

array
The array of paging parameters for the paginated resultset.

prevsource public

prev( string $title '<< Previous' , array $options [] )

Generates a "previous" link for a set of paged records

Options:

  • disabledTitle The text to used when the link is disabled. This defaults to the same text at the active link. Setting to false will cause this method to return ''.
  • escape Whether you want the contents html entity encoded, defaults to true
  • model The model to use, defaults to PaginatorHelper::defaultModel()
  • url An array of additional URL options to use for link generation.
  • templates An array of templates, or template file name containing the templates you'd like to use when generating the link for previous page. The helper's original templates will be restored once prev() is done.

Parameters

string $title optional '<< Previous'
Title for the link. Defaults to '<< Previous'.
array $options optional []
Options for pagination link. See above for list of keys.

Returns

string
A "previous" link or a disabled link.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-jump-links

sortsource public

sort( string $key , string|null $title null , array $options [] )

Generates a sorting link. Sets named parameters for the sort and direction. Handles direction switching automatically.

Options:

  • escape Whether you want the contents html entity encoded, defaults to true.
  • model The model to use, defaults to PaginatorHelper::defaultModel().
  • direction The default direction to use when this link isn't active.
  • lock Lock direction. Will only use the default direction then, defaults to false.

Parameters

string $key
The name of the key that the recordset should be sorted.
string|null $title optional null
Title for the link. If $title is null $key will be used for the title and will be generated by inflection.
array $options optional []
Options for sorting link. See above for list of keys.

Returns

string
A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified key the returned link will sort by 'desc'.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links

sortDirsource public

sortDir( string|null $model null , array $options [] )

Gets the current direction the recordset is sorted

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.
array $options optional []
Options for pagination links. See #options for list of keys.

Returns

string
The direction by which the recordset is being sorted, or null if the results are not currently sorted.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links

sortKeysource public

sortKey( string|null $model null , array $options [] )

Gets the current key by which the recordset is sorted

Parameters

string|null $model optional null
Optional model name. Uses the default if none is specified.
array $options optional []
Options for pagination links. See #options for list of keys.

Returns

string|null
The name of the key by which the recordset is being sorted, or null if the results are not currently sorted.

Link

http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-sort-links

Methods inherited from Cake\View\Helper

__callsource public

__call( string $method , array $params )

Provide non fatal errors on missing method calls.

Parameters

string $method
Method to invoke
array $params
Array of params for the method.

__debugInfosource public

__debugInfo( )

Returns an array that can be used to describe the internal state of this object.

Returns

array
array

__getsource public

__get( string $name )

Lazy loads helpers.

Parameters

string $name
Name of the property being accessed.

Returns

Cake\View\Helper|null
Helper instance if helper with provided name exists

_confirmsource protected

_confirm( string $message , string $okCode , string $cancelCode '' , array $options [] )

Returns a string to be used as onclick handler for confirm dialogs.

Parameters

string $message
Message to be displayed
string $okCode
Code to be executed after user chose 'OK'
string $cancelCode optional ''
Code to be executed after user chose 'Cancel'
array $options optional []
Array of options

Returns

string
onclick JS code

addClasssource public

addClass( array $options [] , string $class null , string $key 'class' )

Adds the given class to the element options

Parameters

array $options optional []
Array options/attributes to add a class to
string $class optional null
The class name being added.
string $key optional 'class'
the key to use for class.

Returns

array
Array of options with $key set.

Methods used from Cake\View\StringTemplateTrait

formatTemplatesource public

formatTemplate( string $name , array $data )

Format a template string with $data

Parameters

string $name
The template name.
array $data
The data to insert.

Returns

string
string

templatersource public

templater( )

templater

Returns

Cake\View\StringTemplate
\Cake\View\StringTemplate

templatessource public

templates( string|null|array $templates null )

Get/set templates to use.

Parameters

string|null|array $templates optional null
null or string allow reading templates. An array allows templates to be added.

Returns

mixed
$this|string|array

Methods used from Cake\Core\InstanceConfigTrait

_configDeletesource protected

_configDelete( string $key )

Delete a single config key

Parameters

string $key
Key to delete.

Throws

Cake\Core\Exception\Exception
if attempting to clobber existing config

_configReadsource protected

_configRead( string|null $key )

Read a config variable

Parameters

string|null $key
Key to read.

Returns

mixed
mixed

_configWritesource protected

_configWrite( string|array $key , mixed $value , boolean|string $merge false )

Write a config variable

Parameters

string|array $key
Key to write to.
mixed $value
Value to write.
boolean|string $merge optional false
True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Throws

Cake\Core\Exception\Exception
if attempting to clobber existing config

configsource public

config( string|array|null $key null , mixed|null $value null , boolean $merge true )

Usage

Reading the whole config:

$this->config();

Reading a specific value:

$this->config('key');

Reading a nested value:

$this->config('some.nested.key');

Setting a specific value:

$this->config('key', $value);

Setting a nested value:

$this->config('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->config(['one' => 'value', 'another' => 'value']);

Parameters

string|array|null $key optional null
The key to get/set, or a complete array of configs.
mixed|null $value optional null
The value to set.
boolean $merge optional true
Whether to recursively merge or overwrite existing config, defaults to true.

Returns

mixed
Config value being read, or the object itself on write operations.

Throws

Cake\Core\Exception\Exception
When trying to set a key that is invalid.

configShallowsource public

configShallow( string|array $key , mixed|null $value null )

Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.

Setting a specific value:

$this->config('key', $value);

Setting a nested value:

$this->config('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->config(['one' => 'value', 'another' => 'value']);

Parameters

string|array $key
The key to set, or a complete array of configs.
mixed|null $value optional null
The value to set.

Returns

mixed
$this The object itself.

Properties summary

$_defaultConfigsource

protected array

Default config for this class

Options: Holds the default options for pagination links

The values that may be specified are:

  • url Url of the action. See Router::url()
  • url['sort'] the key that the recordset is sorted.
  • url['direction'] Direction of the sorting (default: 'asc').
  • url['page'] Page number to use in links.
  • model The name of the model.
  • escape Defines if the title field for the link should be escaped (default: true).

Templates: the templates used by this class

[
    'options' => [],
    'templates' => [
        'nextActive' => '<li class="next"><a rel="next" href="{{url}}">{{text}}</a></li>',
        'nextDisabled' => '<li class="next disabled"><a href="" onclick="return false;">{{text}}</a></li>',
        'prevActive' => '<li class="prev"><a rel="prev" href="{{url}}">{{text}}</a></li>',
        'prevDisabled' => '<li class="prev disabled"><a href="" onclick="return false;">{{text}}</a></li>',
        'counterRange' => '{{start}} - {{end}} of {{count}}',
        'counterPages' => '{{page}} of {{pages}}',
        'first' => '<li class="first"><a href="{{url}}">{{text}}</a></li>',
        'last' => '<li class="last"><a href="{{url}}">{{text}}</a></li>',
        'number' => '<li><a href="{{url}}">{{text}}</a></li>',
        'current' => '<li class="active"><a href="">{{text}}</a></li>',
        'ellipsis' => '<li class="ellipsis">...</li>',
        'sort' => '<a href="{{url}}">{{text}}</a>',
        'sortAsc' => '<a class="asc" href="{{url}}">{{text}}</a>',
        'sortDesc' => '<a class="desc" href="{{url}}">{{text}}</a>',
        'sortAscLocked' => '<a class="asc locked" href="{{url}}">{{text}}</a>',
        'sortDescLocked' => '<a class="desc locked" href="{{url}}">{{text}}</a>',
    ]
]

$_defaultModelsource

protected string

Default model of the paged sets

$helperssource

public array

List of helpers used by this helper

['Url', 'Number', 'Html']

Properties inherited from Cake\View\Helper

$_Viewsource

protected Cake\View\View

The View instance this helper is attached to

$_helperMapsource

protected array

A helper lookup table used to lazy load helper objects.

[]

$fieldsetsource

public array

Holds the fields ['field_name' => ['type' => 'string', 'length' => 100]], primaryKey and validates ['field_name']

[]

$pluginsource

public string

Plugin path

null

$requestsource

public Cake\Network\Request

Request object

null

$tagssource

public array

Holds tag templates.

[]

$themesource

public string

The current theme name if any.

null

Properties used from Cake\Core\InstanceConfigTrait

$_configsource

protected array

Runtime config

[]

$_configInitializedsource

protected boolean

Whether the config property has already been configured with defaults

false

Properties used from Cake\View\StringTemplateTrait

$_templatersource

protected Cake\View\StringTemplate

StringTemplate instance.

Magic properties summary

© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.View.Helper.PaginatorHelper.html