码迷,mamicode.com
首页 > 其他好文 > 详细

phalcon几种分页方法

时间:2016-09-14 18:46:33      阅读:613      评论:0      收藏:0      [点我收藏+]

标签:

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几种分页方法

标签:

原文地址:http://www.cnblogs.com/achengmu/p/5873078.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!