Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 34 | All time: 11,026 This week: 206 |
Version | License | PHP version | Categories | |||
oka-pagination 2.7.0 | MIT/X Consortium ... | 5.3 | HTML, PHP 5, Libraries |
Description | Author | ||||||||
This package is a bundle for pagination support using Twig templates. |
|
This bundle provides a flexible pagination system.
The OkaPaginationBundle has the following requirements: - PHP 5.5 - Symfony 2.7+ - Twig Extension
Installation is a quick (I promise!) 4 step process:
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require coka/pagination-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Oka\PaginationBundle\OkaPaginationBundle(),
);
// ...
}
// ...
}
Add the following configuration to your config.yml
.
# app/config/config.yml
oka_pagination:
db_driver: orm
model_manager_name: default
item_per_page: 10 # Global number of items to show by page
max_page_number: 4000 # Global number max of page to show
template: OkaPaginationBundle:Pagination:paginate.html.twig # Global twig template used for shown pagination menu
request:
query_map:
page: page # Global page query parameter name
item_per_page: item_per_page # Global number of items by page query parameter name
sort: sort # Global sort field query parameter name
desc: desc # Global sort direction query parameter name
sort:
delimiter: ',' # Global sort query delimiter value
attributes_availables: ['name'] # Global sort query value availables attributes
twig:
enable_extension: true
enable_global: false
pagination_managers:
foo:
db_driver: orm
model_manager_name: default
class: Acme\DemoBundle\Entity\Foo
item_per_page: 10
max_page_number: 4000
template: OkaPaginationBundle:Pagination:paginate.html.twig
request:
query_map:
page: page
item_per_page: item_per_page
sort: sort
desc: desc
filters:
name:
type: string
enabled:
field: enabled # Not required if the filter name is equal to the field name
type: boolean # The type in which the value of the filter will be casted
sort:
delimiter: ','
attributes_availables: ['name', 'createdAt']
The goal of this bundle is to paginate some Entity
(ORM) or Document
(MongoDB) class.
You can use it in two ways.
Initialize pagination
// Acme\DemoBundle\Controller\FooController.php
public function listAction(Request $request)
{
/ @var \Oka\PaginationBundle\Service\PaginationManager $pm */
$pm = $this->get('oka_pagination.manager');
// Use default pagination manager
/ @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
$page = $pm->paginate(Foo::class, $request, [], ['name' => 'ASC']);
// Or use custom pagination manager
// / @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
// $page = $pm->paginate('foo', $request, [], ['name' => 'ASC']);
// parameters to template
return $this->render('AcmeDemoBundle:Foo:list.html.twig', ['page' => $page]);
}
{# total items count #}
<div class="count">
{{ page.getFullyItems() }}
</div>
<table>
{# table body #}
{% for item in page.items %}
<tr {% if loop.index is odd %}class="color"{% endif %}>
<td>{{ item.id }}</td>
<td>{{ item.title }}</td>
</tr>
{% endfor %}
</table>
{# display navigation #}
<div class="navigation">
{# Use the current pagination manager #}
{{ paginate('foo_path' , {'query': 'query'}) }}
{# Or use a specific pagination manager #}
{# {{ paginate_foo('foo_path' , {'query': 'query'}) }} #}
</div>
// Acme\DemoBundle\Controller\FooController.php
public function listAction(Request $request)
{
/ @var \Oka\PaginationBundle\Service\PaginationManager $pm */
$pm = $this->get('oka_pagination.manager');
// Use default pagination manager
/ @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
$pm->createQuery('foo', $request, [], ['name' => 'ASC'])
->setCountItemsCallable(function(EntityRepository $er, array $criteria){
// Here your code to return the number of elements
// ...
})
->setSelectItemsCallable(function(EntityRepository $er, array $criteria, array $orderBy, $limit, $offset){
// Here your code to return the elements list
// ...
});
/ @var \Oka\PaginationBundle\Util\PaginationResultSet $page */
$page = $pm->fetch();
// parameters to template
return $this->render('AcmeDemoBundle:Foo:list.html.twig', ['page' => $page]);
}
This bundle provides a flexible pagination system.
For notes about latest changes please read CHANGELOG, for required changes in your code please read UPGRADE chapter of documentation.
Read the Resources/doc/index.md.
All the installation instructions are located in the documentation.
This bundle is under the MIT license. See the complete license in the bundle.
Files (38) |
File | Role | Description | ||
---|---|---|---|---|
src (1 file, 8 directories) | ||||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (38) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Converter (2 files, 3 directories) | ||||
DependencyInjection (2 files) | ||||
Exception (4 files) | ||||
Resources (3 directories) | ||||
Service (4 files) | ||||
Tests (3 directories) | ||||
Twig (1 file) | ||||
Util (4 files) | ||||
OkaPaginationBundle.php | Class | Class source |
Files (38) | / | src | / | Converter |
File | Role | Description | ||
---|---|---|---|---|
DBAL (4 files) | ||||
Mongodb (1 file) | ||||
ORM (3 files) | ||||
AbstractQueryExprConverter.php | Class | Class source | ||
QueryExprConverterInterface.php | Class | Class source |
Files (38) | / | src | / | Converter | / | DBAL |
File | Role | Description |
---|---|---|
EqualQueryExprConverter.php | Class | Class source |
LikeQueryExprConverter.php | Class | Class source |
NotEqualQueryExprConverter.php | Class | Class source |
NotLikeQueryExprConverter.php | Class | Class source |
Files (38) | / | src | / | Converter | / | Mongodb |
File | Role | Description |
---|---|---|
RangeQueryExprConverter.php | Class | Class source |
Files (38) | / | src | / | Converter | / | ORM |
File | Role | Description |
---|---|---|
IsNotNullQueryExprConverter.php | Class | Class source |
IsNullQueryExprConverter.php | Class | Class source |
RangeQueryExprConverter.php | Class | Class source |
Files (38) | / | src | / | DependencyInjection |
File | Role | Description |
---|---|---|
Configuration.php | Class | Class source |
OkaPaginationExtension.php | Class | Class source |
Files (38) | / | src | / | Exception |
File | Role | Description |
---|---|---|
BadQueryExprException.php | Class | Class source |
ObjectManagerNotSupportedException.php | Class | Class source |
PaginationException.php | Class | Class source |
SortAttributeNotAvailableException.php | Class | Class source |
Files (38) | / | src | / | Resources | / | views | / | Pagination |
File | Role | Description |
---|---|---|
paginate.html.twig | Data | Auxiliary data |
Files (38) | / | src | / | Service |
File | Role | Description |
---|---|---|
PaginationManager.php | Class | Class source |
PaginationManagerBag.php | Class | Class source |
QueryBuilderHandler.php | Class | Class source |
QueryBuilderManipulator.php | Class | Class source |
Files (38) | / | src | / | Tests |
Files (38) | / | src | / | Tests | / | Converter |
File | Role | Description | ||
---|---|---|---|---|
ORM (1 file) | ||||
LikeQueryExprConvertertest.php | Class | Class source | ||
NotLikeQueryExprConvertertest.php | Class | Class source |
Files (38) | / | src | / | Tests | / | Converter | / | ORM |
File | Role | Description |
---|---|---|
RangeQueryExprConvertertest.php | Class | Class source |
Files (38) | / | src | / | Tests | / | Service |
File | Role | Description |
---|---|---|
QueryBuilderManipulatorTest.php | Class | Class source |
Files (38) | / | src | / | Util |
File | Role | Description |
---|---|---|
FilterUtil.php | Class | Class source |
PaginationQuery.php | Class | Class source |
PaginationResultSet.php | Class | Class source |
RequestParser.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.