首页 > 代码库 > phalcon几种分页方法

phalcon几种分页方法

phalcon几种分页方法

一:

use Phalcon\Paginator\Adapter\Model as PaginatorModel;// Current page to show// In a controller this can be:// $this->request->getQuery(‘page‘, ‘int‘); // GET// $this->request->getPost(‘page‘, ‘int‘); // POST$currentPage = (int) $_GET["page"];// The data set to paginate$robots      = Robots::find();// Create a Model paginator, show 10 rows by page starting from $currentPage$paginator   = new PaginatorModel(    array(        "data"  => $robots,        "limit" => 10,        "page"  => $currentPage    ));// Get the paginated results$page = $paginator->getPaginate();

  

 

 

二:

use Phalcon\Paginator\Adapter\Model as PaginatorModel;use Phalcon\Paginator\Adapter\NativeArray as PaginatorArray;use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder;// Passing a resultset as data$paginator = new PaginatorModel(    array(        "data"  => Products::find(),        "limit" => 10,        "page"  => $currentPage    ));// Passing an array as data$paginator = new PaginatorArray(    array(        "data"  => array(            array(‘id‘ => 1, ‘name‘ => ‘Artichoke‘),            array(‘id‘ => 2, ‘name‘ => ‘Carrots‘),            array(‘id‘ => 3, ‘name‘ => ‘Beet‘),            array(‘id‘ => 4, ‘name‘ => ‘Lettuce‘),            array(‘id‘ => 5, ‘name‘ => ‘‘)        ),        "limit" => 2,        "page"  => $currentPage    ));// Passing a QueryBuilder as data$builder = $this->modelsManager->createBuilder()    ->columns(‘id, name‘)    ->from(‘Robots‘)    ->orderBy(‘name‘);$paginator = new PaginatorQueryBuilder(    array(        "builder" => $builder,        "limit"   => 20,        "page"    => 1    ));

  

 

phalcon几种分页方法