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
    )
);

  

时间: 2024-09-28 15:46:49

phalcon几种分页方法的相关文章

数据分页 THINKPHP3.2 分页 三种分页方法

数据分页 复制本页链接 opensns 通常在数据查询后都会对数据集进行分页操作,ThinkPHP也提供了分页类来对数据分页提供支持. 下面是数据分页的两种示例. 第一种:利用Page类和limit方法 $User = M('User'); // 实例化User对象 $count = $User->where('status=1')->count();// 查询满足要求的总记录数 $Page = new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的

Sql三种分页方法

--分页三种方法--第一种 ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs 大于pagesize*pageindex,少于等于pagesize*(pageindex+1) --效率最高SELECT * FROM Sys_User AS ALEFT JOIN(SELECT ROW_NUMBER() OVER( ORDER BY OrgID) AS indexs ,ID FROM dbo.Sys_User --效率 次之) AS B ON A.ID = B.

sqlalchemy和flask-sqlalchemy的几种分页方法

sqlalchemy中使用query查询,而flask-sqlalchemy中使用basequery查询,他们是子类与父类的关系 假设 page_index=1,page_size=10:所有分页查询不可以再跟first(),all()等 1.用offset()设置索引偏移量,limit()限制取出量 db.session.query(User.name).filter(User.email.like('%'+email+'%')).limit(page_size).offset((page_i

sqlserver两种分页方法比较

-- 3000 page(从1开始) 10 pagesize -- 方法1(效率不高): SELECT TOP 10 * FROM [xxx].[oooo] WHERE id NOT IN (SELECT TOP (10*(3000-1)) id FROM [xxx].[oooo] ORDER BY createtime DESC)ORDER BY createtime DESC; 方法2(效率高): SELECT TOP 10 * FROM (SELECT ROW_NUMBER() OVER

Sql Server三种分页方法

IF EXISTS(SELECT * FROM SYSOBJECTS WHERE NAME = 'StuWebName') DROP TABLE StuWebName GO CREATE TABLE StuWebName ( StuId INT IDENTITY(1,1) PRIMARY KEY, StuName VARCHAR(50) NOT NULL, StuPassword VARCHAR(50) NOT NULL, StuSex CHAR(2) DEFAULT('男'), StuNo I

SQL SERVER 2008 中三种分页方法与总结

建立表: 1 CREATE TABLE [TestTable] ( 2 [ID] [int] IDENTITY (1, 1) NOT NULL , 3 [FirstName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , 4 [LastName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL , 5 [Country] [nvarchar] (50) COLLATE Chinese_PRC_C

SQL SERVER 分页方法

    最近项目中需要在SQL SERVER中进行分页,需要编写分页查询语句.之前也写过一些关于分页查询的语句,但是性能不敢恭维.于是在业务时间,在微软社区Bing了一篇老外写的关于SQL SERVER分页的文章.看过之后,感觉自己之前写的语句,太低端,太不科学了.  文章中讲了两种分页方法,其中一种只适用于SQL SERVER2012以上版本.   ROW_NUMBER()函数分页  先介绍一下ROW_NUMBER()函数,这个函数的主要作用,从它的命名中就可看出来.ROW,每列,NUMBER

Yii 分页方法

说明:这里介绍两种分页方法案例 1.CListView 2.CLinkPager 第一种CListView分页方法的使用说明: yii框架链接:http://www.php100.com/manual/yii/CListView.html 源代码:framework/zii/widgets/CListView.php 格式如下代码: $dataProvider=new CActiveDataProvider('Post'); $this->widget('zii.widgets.CListVie

php分页类的二种调用方法(转载)

php分页类的二种调用方法 原文地址:http://www.xfcodes.com/php/fenye/25584.htm 导读:php分页类的二种调用用法,ajax调用php分页类,非ajax方式调用php分页类,自定义分页显示模式,允许设置是否支持AJAX分页模式. php分页类的二种调用方法 1,ajax调用php分页类: //$total,总数(int):$size,每页显示数量(int):$page,当前页(int),$url,链接(string):ajax,js函数名:$page =