Cygnite - A Modern Toolkit For Web Developers

The Elegant Way of Building Full-Featured Web Applications

Cygnite Dynamic Routing

Pagination

Documentation

Pagination

Configuration

We believe in painless development. Pagination is completely model based, though you can use it as standalone library. Generating pagination is very simple with almost zero configuration.

Pagination With Model

You just need to set how many records should display per page in your model. Two ways we can set page number.

1. Set page number using model. or

2. Set page number using all() method.

3. Let us consider model is ShoppingProduct.



namespace Apps\Models;

use Cygnite\Common\UrlManager\Url;
use Cygnite\Database\Cyrus\ActiveRecord;

class Product extends ActiveRecord
{
   //your database connection name
   protected $database = 'cygnite';

   protected $primaryKey = 'id';

   public $perPage = 5; // Set Pagination per page

   public function __construct()
   {
       parent::__construct();
   }

   // Set Current Page Number using URL segment
   protected function pageLimit()
   {
       return Url::segment(3);
   }
}

4. If you don't wish to set current page number using model, you can also use finder method to set current page number to pagination.


  
   $products = Product::all(
       array(
           'orderBy' => 'id desc',
           'paginate' => array(
               'limit' => Url::segment(3)
            )
       )
 );

That's all you are done.

Create Pagination Links

Your pagination links will generate with createLinks() and pass into your view page.



  $links = Product::createLinks();  

  $view = View::create('Apps.Views.product.index', [
                'records' => $product,
                'links' => $links,
                'title' => 'Cygnite Framework - Crud Application'
        ]);

   return Response::make($content);


Displaying links into the view page

Render links where you would like to display pagination as below.

 


echo $links;


Manually Creating Pagination

Sometimes you may wish to create pagination manually without using specific model object.You may do it simply creating \Cygnite\Common\Pagination object and setting the inputs to it. For example:

 


 use Cygnite\Common\Pagination;

 $links = Pagination::make(function ($paginator)
 {
    $paginator->setTotalNumberOfPage(15);
    $paginator->setPerPage(5);

    return $paginator->createLinks();
 });

 echo $links;


Follow Us On Facebook Twitter Google+ Linkedin
Released Under The MIT Public License. Copyrights @2012-2017. Powered by- Sanjoy Dey Productions.