Download the PHP package lampager/lampager-cakephp without Composer
On this page you can find all versions of the php package lampager/lampager-cakephp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package lampager-cakephp
Lampager for CakePHP
Rapid pagination without using OFFSET
Requirements
- PHP: ^8.1
- CakePHP: ^5.1
Note
- For CakePHP 2.x, use lampager/lampager-cakephp2.
- For CakePHP 3.x, use lampager/lampager-cakephp v1.x.
- For CakePHP 4.x, use lampager/lampager-cakephp v2.x.
- For CakePHP 5.x, use lampager/lampager-cakephp v3.x (this version).
Installing
For SQLite users, see SQLite to configure.
Basic Usage
Simply install as a Composer package and use in one or more of the following methods:
- Use in Controller (via
\Lampager\Cake\Datasource\Paginator
) - Use in Table (via
\Lampager\Cake\Model\Behavior\LampagerBehavior
)
Use in Controller
At first, configure $paginate
to use \Lampager\Cake\Datasource\Paginator
in
your Controller class.
Use in a way described in the Cookbook: Pagination. Note the options that
are specific to Lampager such as forward
, seekable
, or cursor
.
Use in Table
Initialize LampagerBehavior
in your Table class (AppTable
is preferable)
and simply use lampager()
there.
The query builder (\Lampager\Cake\ORM\Query
) extends the plain old
\Cake\ORM\Query
and is mixed in with \Lampager\Paginator
. Note that some of
the methods in \Lampager\Paginator
, viz., orderBy()
, orderByDesc()
, and
clearOrderBy()
are not exposed because their method signatures are not
compatible with the CakePHP query builder.
The methods from the CakePHP query builder, e.g., where()
, are available.
\Cake\Database\Expression\QueryExpression
is accepted as well.
Classes
See also: lampager/lampager.
Name | Type | Parent Class Implemented Interface |
Description |
---|---|---|---|
Lampager\Cake\ORM\Query |
Class | Cake\ORM\Query |
Fluent factory implementation for CakePHP |
Lampager\Cake\Model\Behavior\LampagerBehavior |
Class | Cake\ORM\Behavior |
CakePHP behavior which returns Lampager\Cake\ORM\Query |
Lampager\Cake\Datasource\Paginator |
Class | Cake\Datasource\Paginator |
CakePHP paginatior which delegates to Lampager\Cake\ORM\Query |
Lampager\Cake\Paginator |
Class | Lampager\Paginator |
Paginator implementation for CakePHP |
Lampager\Cake\ArrayProcessor |
Class | Lampager\ArrayProcessor |
Processor implementation for CakePHP |
Lampager\Cake\PaginationResult |
Class | Lampager\PaginationResult Cake\Datasource\Paging\ PaginatedInterface |
PaginationResult implementation for CakePHP |
Lampager\Cake\Database\SqliteCompiler |
Class | Cake\Database\QueryCompiler |
Query compiler implementation for SQLite |
Lampager\Cake\Database\Driver\Sqlite |
Class | Cake\Database\Driver\Sqlite |
Driver implementation which delegates to Lampager\Cake\Database\SqliteCompiler |
API
See also: lampager/lampager.
LampagerBehavior::lampager()
Build a Lampager query from Table in exactly the same way as CakePHP.
Paginator::__construct()
Paginator::create()
Create a new paginator instance. These methods are not intended to be directly used in your code.
Paginator::transform()
Transform a Lampager query into a CakePHP query.
Paginator::build()
Perform configure + transform.
Paginator::paginate()
Perform configure + transform + process.
Arguments
(mixed)
$cursor
An associative array that contains$column => $value
or an object that implements\Lampager\Contracts\Cursor
. It must be all-or-nothing.- For the initial page, omit this parameter or pass an empty array.
- For the subsequent pages, pass all the parameters. The partial one is not allowed.
Return Value
e.g.,
(Default format when using \Cake\ORM\Query
)
PaginationResult::__call()
\Lampager\Cake\PaginationResult
implements
\Cake\Datasource\Paging\PaginatedInterface
.
Examples
This section describes the practical usage of lampager-cakephp.
Use in Controller
The example below shows how to accept a cursor parameter from a request and pass
it through PaginatorComponent::paginate()
. Be sure that your AppController
has properly initialized Paginator
as above.
And the pagination links can be output as follows:
Supported database engines
MySQL, MariaDB, and PostgreSQL
Supported!
Microsoft SQL Server
Not supported.
SQLite
Supported but requires an additional configuration.
In SQLite UNION ALL
statements cannot combine SELECT
statements that have
ORDER BY
clause. In order to get this to work, those SELECT
statements have
to be wrapped by a subquery like SELECT * FROM (...)
. CakePHP not natively
handling this situation, Lampager for CakePHP introduces
\Lampager\Cake\Database\Driver\Sqlite
that needs to be installed on your
application. Configure like the following in your config/app.php
: