Properties

$helpers

$helpers : array

List of helpers used by this helper

Type

array

$fieldset

$fieldset : array

Unused.

Type

array

$tags

$tags : array

Unused.

Type

array

$Url

$Url : \Cake\View\Helper\UrlHelper

Type

\Cake\View\Helper\UrlHelper

$Number

$Number : \Cake\View\Helper\NumberHelper

Type

\Cake\View\Helper\NumberHelper

$Html

$Html : \Cake\View\Helper\HtmlHelper

Type

\Cake\View\Helper\HtmlHelper

$Form

$Form : \Cake\View\Helper\FormHelper

Type

\Cake\View\Helper\FormHelper

$_defaultConfig

$_defaultConfig : 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

Type

array

$_helperMap

$_helperMap : array

A helper lookup table used to lazy load helper objects.

Type

array

$_View

$_View : \Cake\View\View

The View instance this helper is attached to

Type

\Cake\View\View

$_config

$_config : array

Runtime config

Type

array

$_configInitialized

$_configInitialized : boolean

Whether the config property has already been configured with defaults

Type

boolean

$_defaultModel

$_defaultModel : string

Default model of the paged sets

Type

string

Methods

setTemplates()

setTemplates(array  $templates) : $this

Sets templates to use.

Parameters

array $templates

Templates to be added.

Returns

$this

getTemplates()

getTemplates(string|null  $template = null) : string|array

Gets templates to use or a specific template.

Parameters

string|null $template

String for reading a specific template, null for all.

Returns

string|array

templates()

templates(string|null|array  $templates = null) : $this|string|array

Gets/sets templates to use.

Parameters

string|null|array $templates

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

Returns

$this|string|array

formatTemplate()

formatTemplate(string  $name, array  $data) : string

Formats a template string with $data

Parameters

string $name

The template name.

array $data

The data to insert.

Returns

string

__construct()

__construct(\Cake\View\View  $View, array  $config = array()) 

Constructor. Overridden to merge passed args with URL options.

Parameters

\Cake\View\View $View

The View this helper is being attached to.

array $config

Configuration settings for the helper.

__call()

__call(string  $method, array  $params) : void

Provide non fatal errors on missing method calls.

Parameters

string $method

Method to invoke

array $params

Array of params for the method.

__get()

__get(string  $name) : \Cake\View\Helper|null

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

__set()

__set(string  $name, mixed  $value) : void

Magic setter for removed properties.

Parameters

string $name

Property name.

mixed $value

Value to set.

getView()

getView() : \Cake\View\View

Get the view instance this helper is bound to.

Returns

\Cake\View\View

The bound view instance.

addClass()

addClass(array  $options = array(), string|null  $class = null, string  $key = 'class') : array

Adds the given class to the element options

Parameters

array $options

Array options/attributes to add a class to

string|null $class

The class name being added.

string $key

the key to use for class.

Returns

array —

Array of options with $key set.

implementedEvents()

implementedEvents() : array

Event listeners.

By defining one of the callback methods a helper is assumed to be interested in the related event.

Override this method if you need to add non-conventional event listeners. Or if you want helpers to listen to non-standard events.

Returns

array

initialize()

initialize(array  $config) : void

Constructor hook method.

Implement this method to avoid having to overwrite the constructor and call parent.

Parameters

array $config

The configuration settings provided to this helper.

__debugInfo()

__debugInfo() : array

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

Returns

array

setConfig()

setConfig(string|array  $key, mixed|null  $value = null, boolean  $merge = true) : $this

Sets the config.

Usage

Setting a specific value:

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

Setting a nested value:

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

Updating multiple config settings at the same time:

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

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

$this

getConfig()

getConfig(string|null  $key = null, mixed  $default = null) : mixed

Returns the config.

Usage

Reading the whole config:

$this->getConfig();

Reading a specific value:

$this->getConfig('key');

Reading a nested value:

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

Reading with default value:

$this->getConfig('some-key', 'default-value');

Parameters

string|null $key

The key to get or null for the whole config.

mixed $default

The return value when the key does not exist.

Returns

mixed —

Config value being read.

config()

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

Gets/Sets the config.

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

The key to get/set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

mixed —

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

configShallow()

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

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->configShallow('key', $value);

Setting a nested value:

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

Updating multiple config settings at the same time:

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

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

Returns

$this

params()

params(string|null  $model = null) : array

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

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

Returns

array —

The array of paging parameters for the paginated resultset.

param()

param(string  $key, string|null  $model = null) : mixed

Convenience access to any of the paginator params.

Parameters

string $key

Key of the paginator params array to retrieve.

string|null $model

Optional model name. Uses the default if none is specified.

Returns

mixed —

Content of the requested param.

options()

options(array  $options = array()) : void

Sets default options for all pagination links

Parameters

array $options

Default options for pagination links. See PaginatorHelper::$options for list of keys.

current()

current(string|null  $model = null) : integer

Gets the current page of the recordset for the given model

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

Returns

integer —

The current page number of the recordset.

total()

total(string|null  $model = null) : integer

Gets the total number of pages in the recordset for the given model.

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

Returns

integer —

The total pages for the recordset.

sortKey()

sortKey(string|null  $model = null, array  $options = array()) : string|null

Gets the current key by which the recordset is sorted

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

array $options

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.

sortDir()

sortDir(string|null  $model = null, array  $options = array()) : string

Gets the current direction the recordset is sorted

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

array $options

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.

prev()

prev(string  $title = '<< Previous', array  $options = array()) : string

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

Title for the link. Defaults to '<< Previous'.

array $options

Options for pagination link. See above for list of keys.

Returns

string —

A "previous" link or a disabled link.

next()

next(string  $title = 'Next >>', array  $options = array()) : string

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

Title for the link. Defaults to 'Next >>'.

array $options

Options for pagination link. See above for list of keys.

Returns

string —

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

sort()

sort(string  $key, string|null  $title = null, array  $options = array()) : string

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

Title for the link. If $title is null $key will be used for the title and will be generated by inflection.

array $options

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'.

generateUrl()

generateUrl(array  $options = array(), string|null  $model = null, array  $urlOptions = array()) : string

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

Url options:

  • escape: If false, the URL will be returned unescaped, do only use if it is manually escaped afterwards before being displayed.
  • fullBase: If true, the full base URL will be prepended to the result

Parameters

array $options

Pagination/URL options array

string|null $model

Which model to paginate on

array $urlOptions

Array of options The bool version of this argument is deprecated and will be removed in 4.0.0

Returns

string —

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

generateUrlParams()

generateUrlParams(array  $options = array(), string|null  $model = null) : array

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

Parameters

array $options

Pagination/URL options array

string|null $model

Which model to paginate on

Returns

array —

An array of URL parameters

hasPrev()

hasPrev(string|null  $model = null) : boolean

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

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

Returns

boolean —

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

hasNext()

hasNext(string|null  $model = null) : boolean

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

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

Returns

boolean —

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

hasPage()

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

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

Parameters

string|null $model

Optional model name. Uses the default if none is specified.

integer $page

The page number - if not set defaults to 1.

Returns

boolean —

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

defaultModel()

defaultModel(string|null  $model = null) : string|null

Gets or sets the default model of the paged sets

Parameters

string|null $model

Model name to set

Returns

string|null —

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

counter()

counter(string|array  $options = array()) : string

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

Options for the counter string. See #options for list of keys. If string it will be used as format.

Returns

string —

Counter string.

numbers()

numbers(array  $options = array()) : string|false

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

Options for the numbers.

Returns

string|false —

Numbers string.

first()

first(string|integer  $first = '<< first', array  $options = array()) : string|false

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

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

An array of options.

Returns

string|false —

Numbers string.

last()

last(string|integer  $last = 'last >>', array  $options = array()) : string|false

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

if string use as label for the link, if numeric print page numbers

array $options

Array of options

Returns

string|false —

Numbers string.

meta()

meta(array  $options = array()) : string|null

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/absent to return as a string
  • prev (default True) True to generate meta for previous page
  • next (default True) True to generate meta for next page
  • first (default False) True to generate meta for first page
  • last (default False) True to generate meta for last page

Parameters

array $options

Array of options

Returns

string|null —

Meta links

limitControl()

limitControl(array  $limits = array(), integer|null  $default = null, array  $options = array()) : string

Dropdown select for pagination limit.

This will generate a wrapping form.

Parameters

array $limits

The options array.

integer|null $default

Default option for pagination limit. Defaults to $this->param('perPage').

array $options

Options for Select tag attributes like class, id or event

Returns

string —

html output.

_confirm()

_confirm(string  $message, string  $okCode, string  $cancelCode = '', array  $options = array()) : string

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

Code to be executed after user chose 'Cancel'

array $options

Array of options

Returns

string —

onclick JS code

_cleanConfirmMessage()

_cleanConfirmMessage(string  $message) : mixed

Returns a string read to be used in confirm()

Parameters

string $message

The message to clean

Returns

mixed

_configRead()

_configRead(string|null  $key) : mixed

Reads a config key.

Parameters

string|null $key

Key to read.

Returns

mixed

_configWrite()

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

Writes a config key.

Parameters

string|array $key

Key to write to.

mixed $value

Value to write.

boolean|string $merge

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

_configDelete()

_configDelete(string  $key) : void

Deletes a single config key.

Parameters

string $key

Key to delete.

Throws

\Cake\Core\Exception\Exception

if attempting to clobber existing config

_toggledLink()

_toggledLink(string|boolean  $text, boolean  $enabled, array  $options, array  $templates) : string

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

_removeAlias()

_removeAlias(string  $field, string|null  $model = null) : string

Remove alias if needed.

Parameters

string $field

Current field

string|null $model

Current model alias

Returns

string —

Unaliased field if applicable

_hasPage()

_hasPage(string  $model, integer  $page) : boolean

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

_getNumbersStartAndEnd()

_getNumbersStartAndEnd(array  $params, array  $options) : array

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.

_formatNumber()

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

Formats a number for the paginator number output.

Parameters

\Cake\View\StringTemplate $templater

StringTemplate instance.

array $options

Options from the numbers() method.

Returns

string

_modulusNumbers()

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

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.

_firstNumber()

_firstNumber(string  $ellipsis, array  $params, integer  $start, array  $options) : string

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

Parameters

string $ellipsis

Ellipsis character.

array $params

Params from the numbers() method.

integer $start

Start number.

array $options

Options from the numbers() method.

Returns

string —

Markup output.

_lastNumber()

_lastNumber(string  $ellipsis, array  $params, integer  $end, array  $options) : string

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

Parameters

string $ellipsis

Ellipsis character.

array $params

Params from the numbers() method.

integer $end

End number.

array $options

Options from the numbers() method.

Returns

string —

Markup output.

_numbers()

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

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.