phalcon几种分页方法

Posted 穆晟铭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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几种分页方法的主要内容,如果未能解决你的问题,请参考以下文章

几种分页存储过程

常见的几种分页--总结在于坚持

Sql Server 常见的几种分页方式

phalcon: 缓存片段,文件缓存,memcache缓存

MyBatis的三种分页方式,你用过几种?

MyBatis的三种分页方式,你用过几种?