PHP分页代码

    /*
     * 获取所有商品
     * GET /api/lottery/prize
     */
    public function actionRestlist() {
        $this->checkRestAuth();


        $prizes = array();
        // 分页
        $curPage = 1;
        $offset = 0;
        $limit = 100;


        if (isset($_GET['curPage'])) {
            $curPage = abs(intval($_GET['curPage']));
        }
        if (isset($_GET['limit'])) {
            $limit = abs(intval($_GET['limit']));
        }

        $criteria = new CDbCriteria;
        $criteria->compare('archived', 1);
        $criteria->limit = $limit;
        $criteria->offset = ($curPage - 1) * $limit;
        // 分页
        $json = new JsonData();
        $json->limit = $limit;
        $json->curPage = $curPage;
        $json->total = LotteryPrize::model()->count($criteria);
        $json->result = $this->JSONArrayMapper(LotteryPrize::model()->findAll($criteria));
        echo CJSON::encode($json);
    }

  //测试奖品清单的分页
        var firstReplyId;
        var secReplyId;
        it('success to get lottery prize list paging', function(done) {
            async.series({
                action: function(callback) {
                    base.get('/api/lottery/prize?curPage=1&limit=2', {
                        token: 'basic-valid'
                    }).then(function(results) {
                        firstReplyId = results.result[0].id;
                        secReplyId = results.result[1].id;
                        done();
                    }, function(err) {
                        console.error(err);
                        callback(new Error('can not get lottery prize list paging'));
                    });
                }
            }, function(err, results) {
                done(err);
            });
        });it('success to test lottery prize first paging', function(done) {
            async.series({
                action: function(callback) {
                    base.get('/api/lottery/prize?curPage=1&limit=1', {
                        token: 'basic-valid'
                    }).then(function(results) {
                        assert.equal(results.result.length, 1);
                        assert.equal(results.result[0].id, firstReplyId);
                        done();
                    }, function(err) {
                        console.error(err);
                        callback(new Error('can not get lottery prize first paging'));
                    });
                }
            }, function(err, results) {
                done(err);
            });
        });it('success to get lottery prize second paging', function(done) {
            async.series({
                action: function(callback) {
                    base.get('/api/lottery/prize?curPage=2&limit=1', {
                        token: 'basic-valid'
                    }).then(function(results) {
                        assert.equal(results.result.length, 1);
                        assert.equal(results.result[0].id, secReplyId);
                        done();
                    }, function(err) {
                        console.error(err);
                        callback(new Error('can not get lottery prize second paging'));
                    });
                }
            }, function(err, results) {
                done(err);
            });
        });
    });
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值