Pagination Helper class for easy generation of pagination links.
PaginationHelper encloses all methods needed when working with pagination.
Cake\View\Helper\FormHelper
Cake\View\Helper\HtmlHelper
Cake\View\Helper\NumberHelper
Cake\View\Helper\UrlHelper
Cake\View\View
The View instance this helper is attached to
array<string, mixed>
Runtime config
bool
Whether the config property has already been configured with defaults
array<string, mixed>
Default config for this class
string|null
Default model of the paged sets
array<string, array>
A helper lookup table used to lazy load helper objects.
Cake\View\StringTemplate|null
StringTemplate instance.
array
List of helpers used by this helper
Provide non fatal errors on missing method calls.
Constructor. Overridden to merge passed args with URL options.
Returns an array that can be used to describe the internal state of this object.
Lazy loads helpers.
Deletes a single config key.
Reads a config key.
Writes a config key.
Returns a string to be used as onclick handler for confirm dialogs.
Generates the first number for the paginator numbers() method.
Formats a number for the paginator number output.
Calculates the start and end for the pagination numbers.
Does $model have $page in its range?
Generates the last number for the paginator numbers() method.
Generates the numbers for the paginator numbers() method.
Generates the numbers for the paginator numbers() method.
Remove alias if needed.
Generate an active/inactive link for next/prev methods.
Adds the given class to the element options
Merge provided config with existing config. Unlike config()
which does a recursive merge for nested keys, this method does a simple merge.
Returns a counter string for the paged result set.
Gets the current page of the recordset for the given model
Gets or sets the default model of the paged sets
Returns a first or set of numbers for the first pages.
Formats a template string with $data
Merges passed URL options with current pagination state to generate a pagination URL.
Merges passed URL options with current pagination state to generate a pagination URL.
Returns the config.
Returns the config for this specific key.
Gets templates to use or a specific template.
Get the view instance this helper is bound to.
Returns true if the given result set is not at the last page
Returns true if the given result set has the page number given by $page
Returns true if the given result set is not at the first page
Event listeners.
Constructor hook method.
Returns a last or set of numbers for the last pages.
Dropdown select for pagination limit. This will generate a wrapping form.
Returns the meta-links for a paginated result set.
Generates a "next" link for a set of paged records
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).
Sets default options for all pagination links
Convenience access to any of the paginator params.
Gets the current paging parameters from the resultset for the given model
Generates a "previous" link for a set of paged records
Sets the config.
Sets templates to use.
Generates a sorting link. Sets named parameters for the sort and direction. Handles direction switching automatically.
Gets the current direction the recordset is sorted
Gets the current key by which the recordset is sorted
Returns the templater instance.
Gets the total number of pages in the recordset for the given model.
__call(string $method, array $params): mixed|void
Provide non fatal errors on missing method calls.
string
$method Method to invoke
array
$params Array of params for the method.
mixed|void
__construct(Cake\View\View $view, array<string, mixed> $config = [])
Constructor. Overridden to merge passed args with URL options.
Cake\View\View
$view The View this helper is being attached to.
array<string, mixed>
$config optional Configuration settings for the helper.
__debugInfo(): array<string, mixed>
Returns an array that can be used to describe the internal state of this object.
array<string, mixed>
__get(string $name): Cake\View\Helper|null|void
Lazy loads helpers.
string
$name Name of the property being accessed.
Cake\View\Helper|null|void
_configDelete(string $key): void
Deletes a single config key.
string
$key Key to delete.
void
Cake\Core\Exception\CakeException
_configRead(string|null $key): mixed
Reads a config key.
string|null
$key Key to read.
mixed
_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void
Writes a config key.
array<string, mixed>|string
$key Key to write to.
mixed
$value Value to write.
string|bool
$merge optional True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
void
Cake\Core\Exception\CakeException
_confirm(string $okCode, string $cancelCode): string
Returns a string to be used as onclick handler for confirm dialogs.
string
$okCode Code to be executed after user chose 'OK'
string
$cancelCode Code to be executed after user chose 'Cancel'
string
_firstNumber(string $ellipsis, array<string, mixed> $params, int $start, array<string, mixed> $options): string
Generates the first number for the paginator numbers() method.
string
$ellipsis Ellipsis character.
array<string, mixed>
$params Params from the numbers() method.
int
$start Start number.
array<string, mixed>
$options Options from the numbers() method.
string
_formatNumber(Cake\View\StringTemplate $templater, array<string, mixed> $options): string
Formats a number for the paginator number output.
Cake\View\StringTemplate
$templater StringTemplate instance.
array<string, mixed>
$options Options from the numbers() method.
string
_getNumbersStartAndEnd(array<string, mixed> $params, array<string, mixed> $options): array
Calculates the start and end for the pagination numbers.
array<string, mixed>
$params Params from the numbers() method.
array<string, mixed>
$options Options from the numbers() method.
array
_hasPage(string|null $model, string $dir): bool
Does $model have $page in its range?
string|null
$model Model name to get parameters for.
string
$dir Direction
bool
_lastNumber(string $ellipsis, array<string, mixed> $params, int $end, array<string, mixed> $options): string
Generates the last number for the paginator numbers() method.
string
$ellipsis Ellipsis character.
array<string, mixed>
$params Params from the numbers() method.
int
$end End number.
array<string, mixed>
$options Options from the numbers() method.
string
_modulusNumbers(Cake\View\StringTemplate $templater, array<string, mixed> $params, array<string, mixed> $options): string
Generates the numbers for the paginator numbers() method.
Cake\View\StringTemplate
$templater StringTemplate instance.
array<string, mixed>
$params Params from the numbers() method.
array<string, mixed>
$options Options from the numbers() method.
string
_numbers(Cake\View\StringTemplate $templater, array<string, mixed> $params, array<string, mixed> $options): string
Generates the numbers for the paginator numbers() method.
Cake\View\StringTemplate
$templater StringTemplate instance.
array<string, mixed>
$params Params from the numbers() method.
array<string, mixed>
$options Options from the numbers() method.
string
_removeAlias(string $field, string|null $model = null): string
Remove alias if needed.
string
$field Current field
string|null
$model optional Current model alias
string
_toggledLink(string|false $text, bool $enabled, array<string, mixed> $options, array<string, mixed> $templates): string
Generate an active/inactive link for next/prev methods.
string|false
$text The enabled text for the link.
bool
$enabled Whether the enabled/disabled version should be created.
array<string, mixed>
$options An array of options from the calling method.
array<string, mixed>
$templates An array of templates with the 'active' and 'disabled' keys.
string
addClass(array<string, mixed> $options, string $class, string $key = 'class'): array<string, mixed>
Adds the given class to the element options
array<string, mixed>
$options Array options/attributes to add a class to
string
$class The class name being added.
string
$key optional the key to use for class. Defaults to 'class'
.
array<string, mixed>
configShallow(array<string, mixed>|string $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']);
array<string, mixed>|string
$key The key to set, or a complete array of configs.
mixed|null
$value optional The value to set.
$this
counter(string $format = 'pages', array<string, mixed> $options = []): string
Returns a counter string for the paged result set.
model
The model to use, defaults to PaginatorHelper::defaultModel();string
$format optional 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.
array<string, mixed>
$options optional Options for the counter string. See #options for list of keys. If string it will be used as format.
string
current(string|null $model = null): int
Gets the current page of the recordset for the given model
string|null
$model optional Optional model name. Uses the default if none is specified.
int
defaultModel(string|null $model = null): string|null
Gets or sets the default model of the paged sets
string|null
$model optional Model name to set
string|null
first(string|int $first = '<< first', array<string, mixed> $options = []): string
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.
model
The model to use defaults to PaginatorHelper::defaultModel()escape
Whether to HTML escape the text.url
An array of additional URL options to use for link generation.string|int
$first optional if string use as label for the link. If numeric, the number of page links you want at the beginning of the range.
array<string, mixed>
$options optional An array of options.
string
formatTemplate(string $name, array<string, mixed> $data): string
Formats a template string with $data
string
$name The template name.
array<string, mixed>
$data The data to insert.
string
generateUrl(array<string, mixed> $options = [], string|null $model = null, array $url = [], array<string, mixed> $urlOptions = []): string
Merges passed URL options with current pagination state to generate a pagination URL.
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 resultarray<string, mixed>
$options optional Pagination options.
string|null
$model optional Which model to paginate on
array
$url optional URL.
array<string, mixed>
$urlOptions optional Array of options
string
generateUrlParams(array<string, mixed> $options = [], string|null $model = null, array $url = []): array
Merges passed URL options with current pagination state to generate a pagination URL.
array<string, mixed>
$options optional Pagination/URL options array
string|null
$model optional Which model to paginate on
array
$url optional URL.
array
getConfig(string|null $key = null, mixed $default = null): mixed
Returns the config.
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');
string|null
$key optional The key to get or null for the whole config.
mixed
$default optional The return value when the key does not exist.
mixed
getConfigOrFail(string $key): mixed
Returns the config for this specific key.
The config value for this key must exist, it can never be null.
string
$key The key to get.
mixed
InvalidArgumentException
getTemplates(string|null $template = null): array|string
Gets templates to use or a specific template.
string|null
$template optional String for reading a specific template, null for all.
array|string
getView(): Cake\View\View
Get the view instance this helper is bound to.
Cake\View\View
hasNext(string|null $model = null): bool
Returns true if the given result set is not at the last page
string|null
$model optional Optional model name. Uses the default if none is specified.
bool
hasPage(int $page = 1, string|null $model = null): bool
Returns true if the given result set has the page number given by $page
int
$page optional The page number - if not set defaults to 1.
string|null
$model optional Optional model name. Uses the default if none is specified.
bool
InvalidArgumentException
hasPrev(string|null $model = null): bool
Returns true if the given result set is not at the first page
string|null
$model optional Optional model name. Uses the default if none is specified.
bool
implementedEvents(): array<string, mixed>
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.
array<string, mixed>
initialize(array<string, mixed> $config): void
Constructor hook method.
Implement this method to avoid having to overwrite the constructor and call parent.
array<string, mixed>
$config The configuration settings provided to this helper.
void
last(string|int $last = 'last >>', array<string, mixed> $options = []): string
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.
model
The model to use defaults to PaginatorHelper::defaultModel()escape
Whether to HTML escape the text.url
An array of additional URL options to use for link generation.string|int
$last optional if string use as label for the link, if numeric print page numbers
array<string, mixed>
$options optional Array of options
string
limitControl(array<string, string> $limits = [], int|null $default = null, array<string, mixed> $options = []): string
Dropdown select for pagination limit. This will generate a wrapping form.
array<string, string>
$limits optional The options array.
int|null
$default optional Default option for pagination limit. Defaults to $this->param('perPage')
.
array<string, mixed>
$options optional Options for Select tag attributes like class, id or event
string
meta(array<string, mixed> $options = []): 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.
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 stringprev
(default True) True to generate meta for previous pagenext
(default True) True to generate meta for next pagefirst
(default False) True to generate meta for first pagelast
(default False) True to generate meta for last pagearray<string, mixed>
$options optional Array of options
string|null
next(string $title = 'Next >>', array<string, mixed> $options = []): string
Generates a "next" link for a set of paged records
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 truemodel
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.string
$title optional Title for the link. Defaults to 'Next >>'.
array<string, mixed>
$options optional Options for pagination link. See above for list of keys.
string
numbers(array<string, mixed> $options = []): string
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.
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.
array<string, mixed>
$options optional Options for the numbers.
string
options(array<string, mixed> $options = []): void
Sets default options for all pagination links
array<string, mixed>
$options optional Default options for pagination links. See PaginatorHelper::$options for list of keys.
void
param(string $key, string|null $model = null): mixed
Convenience access to any of the paginator params.
string
$key Key of the paginator params array to retrieve.
string|null
$model optional Optional model name. Uses the default if none is specified.
mixed
params(string|null $model = null): array
Gets the current paging parameters from the resultset for the given model
string|null
$model optional Optional model name. Uses the default if none is specified.
array
prev(string $title = '<< Previous', array<string, mixed> $options = []): string
Generates a "previous" link for a set of paged records
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 truemodel
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.string
$title optional Title for the link. Defaults to '<< Previous'.
array<string, mixed>
$options optional Options for pagination link. See above for list of keys.
string
setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this
Sets the config.
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']);
array<string, mixed>|string
$key The key to set, or a complete array of configs.
mixed|null
$value optional The value to set.
bool
$merge optional Whether to recursively merge or overwrite existing config, defaults to true.
$this
Cake\Core\Exception\CakeException
setTemplates(array<string> $templates): $this
Sets templates to use.
array<string>
$templates Templates to be added.
$this
sort(string $key, array<string, mixed>|string|null $title = null, array<string, mixed> $options = []): string
Generates a sorting link. Sets named parameters for the sort and direction. Handles direction switching automatically.
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.string
$key The name of the key that the recordset should be sorted.
array<string, mixed>|string|null
$title optional Title for the link. If $title is null $key will be used for the title and will be generated by inflection. It can also be an array with keys asc
and desc
for specifying separate titles based on the direction.
array<string, mixed>
$options optional Options for sorting link. See above for list of keys.
string
sortDir(string|null $model = null, array<string, mixed> $options = []): string
Gets the current direction the recordset is sorted
string|null
$model optional Optional model name. Uses the default if none is specified.
array<string, mixed>
$options optional Options for pagination links.
string
sortKey(string|null $model = null, array<string, mixed> $options = []): string|null
Gets the current key by which the recordset is sorted
string|null
$model optional Optional model name. Uses the default if none is specified.
array<string, mixed>
$options optional Options for pagination links.
string|null
templater(): Cake\View\StringTemplate
Returns the templater instance.
Cake\View\StringTemplate
total(string|null $model = null): int
Gets the total number of pages in the recordset for the given model.
string|null
$model optional Optional model name. Uses the default if none is specified.
int
Cake\View\Helper\FormHelper
Cake\View\Helper\HtmlHelper
Cake\View\Helper\NumberHelper
Cake\View\Helper\UrlHelper
The View instance this helper is attached to
Cake\View\View
Runtime config
array<string, mixed>
Whether the config property has already been configured with defaults
bool
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).routePlaceholders
An array specifying which paging params should be passed as route placeholders instead of query string parameters. The array can have values 'sort'
, 'direction'
, 'page'
.Templates: the templates used by this class
array<string, mixed>
Default model of the paged sets
string|null
A helper lookup table used to lazy load helper objects.
array<string, array>
StringTemplate instance.
Cake\View\StringTemplate|null
List of helpers used by this helper
array
© 2005–present 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.
https://api.cakephp.org/4.4/class-Cake.View.Helper.PaginatorHelper.html