博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
yii分页函数例子
阅读量:5942 次
发布时间:2019-06-19

本文共 2586 字,大约阅读时间需要 8 分钟。

分页的函数例子

public function actionIndex($perPage = 20, $type = null, $isWeek = 0)    {           Yii::$app->response->format = Response::FORMAT_JSON;                    //判断周末非周末        $weekWhere = $isWeek == 0 ? ['>','start_time',getLastEndTime()]: ['<','start_time',getLastEndTime()];        // 判断互动的类型是否为全部或单独的活动类型        $typeWhere = $type > 0 ? ['type_id' => $type]: '';        $query = Activity::find()                ->with([                'type',                'tags',                'question',                'user',                'answerList',                'feedbackList'                ])                ->asArray()                ->where(                        ['and',                            ['in', 'status', [                                Activity::STATUS_DRAFT,                                Activity::STATUS_RELEASE,                                Activity::STATUS_PREVENT,                                Activity::STATUS_SHUT,                                Activity::STATUS_CANCEL,                            ]],                            $weekWhere,                            $typeWhere,                        ]                    )                ->orderBy($this->activity_order);                $countQuery = clone $query;        $pagination = new Pagination([            'totalCount' => $countQuery->count(),            'pageSize' => $perPage        ]);        // 总页数        $totalCount =  $pagination->totalCount;        // 活动的数据        $activities = $query->offset($pagination->offset)        ->limit($pagination->limit)        ->all();        foreach ($activities as $key => $activity) {            $activities[$key]['answer_count'] = count($activity['answerList']);            $activities[$key]['feedback_count'] = count($activity['feedbackList']);            $activities[$key]['preview_url'] = Yii::$app->params['domain'].'preview/'.$activity['id'];            $activities[$key]['filter_url'] = Yii::$app->params['domain'].'filter/'.$activity['id'];            //set last week days            $activities[$key]['this_week'] = getLastEndTime() < $activity['end_time'] ? 1 : 0;        }        return [            'totalCount' => $totalCount,            'activities' => $activities,        ];     }

注意当前页数是yii内置的,访问这个参数的时候,直接传参数page就可以!

前台代码 angular框架

fetchPage: function(type, page, isWeek) {    page = page || 1;    var params = {        'type': type,        'page': page,        'isWeek': isWeek,        'perPage': 10 //每页20条    };    return $http.get('/activity', {        params: params    }).then(function(data) {        return data;    }); }

转载地址:http://usqtx.baihongyu.com/

你可能感兴趣的文章
关于吃掉物理的二次聚合无法实现的需要之旁门左道实现法
查看>>
mysql出现unblock with 'mysqladmin flush-hosts'
查看>>
oracle exp/imp命令详解
查看>>
开发安全的 API 所需要核对的清单
查看>>
Mycat源码中的单例模式
查看>>
WPF Dispatcher介绍
查看>>
fiddler展示serverIP方法
查看>>
C语言中的随意跳转
查看>>
006-spring cloud gateway-GatewayAutoConfiguration核心配置-GatewayProperties初始化加载、Route初始化加载...
查看>>
WPF中如何将ListViewItem双击事件绑定到Command
查看>>
《聚散两依依》
查看>>
小tips:你不知道的 npm init
查看>>
Mac笔记本中是用Idea开发工具在Java项目中调用python脚本遇到的环境变量问题解决...
查看>>
Jmeter也能IP欺骗!
查看>>
Rust 阴阳谜题,及纯基于代码的分析与化简
查看>>
ASP.NET Core的身份认证框架IdentityServer4(4)- 支持的规范
查看>>
(原創) array可以使用reference方式傳進function嗎? (C/C++)
查看>>
170多个Ionic Framework学习资源(转载)
查看>>
Azure:不能把同一个certificate同时用于Azure Management和RDP
查看>>
Directx11教程(15) D3D11管线(4)
查看>>