dev-master
9999999-dev https://github.com/theDisco/li3_paginationPagination helper for the Lithium PHP framework
BSD-3-Clause
The Requires
- php >=5.3.6
- unionofrad/lithium >=0.10
pagination lithium
Pagination helper for the Lithium PHP framework
li3_pagination was designed to facilitate generating of pagination for Lithium Framework projects. So far helper can generate a pagination from a record set for the current context or from an arbitrary record count. You cannot provide custom arguments for the route generation. Helper cannot extract the query from the provided record set either. It is planed to extend the behavior of the helper to support custom route parameters., (*1)
Clone this repo into the libraries
folder of your project., (*2)
cd /path/to/app/libraries git clone https://github.com/theDisco/li3_pagination.git
Before you can use this helper, you need to tell lithium to load this extension. The best way to do it is to add it as a library in the bootstrap process:, (*3)
``` php false)); // ... ``` You also need to inform Lithium how to map the page param from the request. You can use the example route below or change it according to your needs: ``` php request->page ?: 1; $options = compact('limit', 'page'); $binding = Posts::find('all', $options); return compact('binding', 'options'); } // ... ?>, (*4)
In your view you just need to add following code: ``` php <?php echo $this->pagination->create($binding, $options); echo $this->pagination->first(); echo $this->pagination->previous(); echo $this->pagination->pages(); echo $this->pagination->next(); echo $this->pagination->last(); echo $this->pagination->end(); ?>
You can also use the compound methods for creating the first, previous, next and last page., (*5)
``` php pagination->create($binding, $options); echo $this->pagination->pre(); echo $this->pagination->pages(); echo $this->pagination->post(); echo $this->pagination->end(); ?>, (*6)
By default li3_pagination renders the pages even if only one page is present in pagination. If you want to hide the pagination you can use following syntax: ``` php <?php if ($this->pagination->create($binding, $options + array('start' => false))->count() > 1) { echo $this->pagination->start(); echo $this->pagination->pre(); echo $this->pagination->pages(); echo $this->pagination->post(); echo $this->pagination->end(); } ?>
li3_pagination does not have a constructor and is really similar in the usage to the form helper provided with the Lithium
Framework. Create method takes a binding as the first argument and an array of options as the second argument. You can define
any class as the binding as long as it implements the method model()
. The value returned by model()
method has to be
a string or an object you can use to invoke the method count()
. Basically the \lithium\data\collection\RecordSet
is
the perfect candidate as the first argument. Second argument is an array of options., (*7)
If you have defined any conditions for your model, li3_pagination won't be able to retrieve the correct count. In this case
you can provide the records count as the first argument of create()
method., (*8)
``` php pagination->create('150', $options); ?>, (*9)
Configuration and Options ------------------------- ``` php $options = array( 'page' => 1, 'limit' => 20, 'start' => true, );
TODO Document the options, (*10)
Pagination helper for the Lithium PHP framework
BSD-3-Clause
pagination lithium