public setPageSize ( integer $value, boolean $validatePageSize = false ) | ||
$value | integer | the number of items per page. |
$validatePageSize | boolean | whether to validate page size. |
public static function getPagedRows($query, $tablename, $params, $config = []) { $countQuery = clone $query; if (isset($params['SqlAttackSearch']) || isset($params['SqlLogSearch']) || isset($params['ErrorLogSearch'])) { //$rownums['nums'] = $countQuery->count(); //在条件查询时不处理分页,给一个大概数 $rownums['nums'] = 10000000; } else { $rownums = Yii::$app->db->createCommand("select TABLE_ROWS nums from information_schema.TABLES where TABLE_SCHEMA='Tuandai_Log' and TABLE_NAME='" . $tablename . "'")->queryOne(); } $pages = new Pagination(['totalCount' => $rownums['nums']]); if (isset($config['pageSize'])) { $pages->setPageSize($config['pageSize'], true); } $rows = $query->offset($pages->offset)->limit($pages->limit); if (isset($config['orderBy'])) { $rows = $rows->orderBy($config['orderBy']); } $rows = $rows->all(); $rowsLable = 'datas'; $pagesLable = 'pager'; if (isset($config['rows'])) { $rowsLable = $config['rows']; } if (isset($config['pages'])) { $pagesLable = $config['pages']; } $ret = []; $ret[$rowsLable] = $rows; $ret[$pagesLable] = $pages; return $ret; }
public function actionSearch($keyword, $category_id = NULL, $order = NULL, $image_only = NULL, $h24_only = NULL) { $this->layout = 'create_list'; $key = explode(' ', $keyword); $key = array_filter($key); $info_c = Info::find()->select(['category_id'])->where(['or like', 'title', $key])->groupBy(['category_id'])->all(); $query = Info::find(); if ($category_id) { $query->where(['and', ['category_id' => $category_id], ['or like', 'title', $key]]); } else { $query->where(['and', ['category_id' => isset($info_c[0]) ? $info_c[0]->category_id : ''], ['or like', 'title', $key]]); } if ($image_only) { $query->andWhere(['and', 'photo is not null']); } if ($h24_only) { $query->andWhere(['and', 'time > ' . strtotime("-1 day")]); } if ($order) { $query->orderBy(str_replace('_', ' ', $order)); } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10, true); $data = $query->offset($pages->offset)->limit($pages->limit)->all(); foreach ($key as $k => $v) { $key[$k] = "/(" . $v . ")/i"; } foreach ($data as $k => $v) { $data[$k]->title = preg_replace($key, "<span style='color:red;'>\$1</span>", $data[$k]->title); } return $this->render('search', ['info_c' => $info_c, 'data' => $data, 'pages' => $pages]); }
/** * Shows user's profile. * @param integer $id * @return \yii\web\Response * @throws \yii\web\NotFoundHttpException */ public function actionShow($id) { $this->enableCsrfValidation = false; $profile = $this->finder->findProfileById($id); if ($profile === null) { throw new NotFoundHttpException(); } $query = Comments::find()->where(['deleted' => Comments::NO_DELETED, 'user_id' => $id])->orderBy('created_at'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $comments = $query->offset($pages->offset)->limit($pages->limit)->all(); $model = new Comments(); $this->performAjaxValidation($model); $user = User::findOne(Yii::$app->user->getId()); if ($model->load(Yii::$app->request->post())) { $model->created_at = time(); $model->user_id = $profile->user->getId(); $model->sender_id = Yii::$app->user->getId(); $model->save(); return $this->refresh(); } else { return $this->render('show', ['profile' => $profile, 'model' => $model, 'user' => $user, 'comments' => $comments, 'pages' => $pages]); } return $this->render('show', ['profile' => $profile]); }
/** * @return Pagination */ public function getPaginator() { $paginator = new Pagination(['totalCount' => $this->countQuery->count()]); $paginator->pageParam = 'page'; $paginator->pageSizeParam = false; $paginator->setPageSize($this->limit); return $paginator; }
/** * 个人歌单 * @param $userId * @return array */ public function personalSongKingdomByUserId($userId) { $query = SongKingdom::find()->andWhere(['created_by' => $userId]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return ['models' => $models, 'pages' => $pages, 'userCreadedBy' => User::find()->andWhere(['id' => $userId])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $userId])->asArray()->one()]; }
public function actionIndex() { $query = Ads::find()->where(['deleted' => Ads::NO_DELETED])->orderBy('created_at'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(20); $ads = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['ads' => $ads, 'pages' => $pages]); }
/** * sitemap * @return string */ public function actionSitemap() { /* header */ Yii::$app->response->format = Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); /* ok */ $query = PageData::find()->select(['id_page', 'language', 'updated_at'])->where(['status' => PageData::STATUS_ACTIVE]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(Yii::$app->params['sitemapPageSize']); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->renderPartial('sitemap', ['models' => $models]); }
public function actionTypes() { $current_mode = 1; if (Yii::$app->request->get('mode')) { $current_mode = Yii::$app->request->get('mode'); } $features_types_model = new FeaturesTypes(); if ($features_types_model->load(Yii::$app->request->post())) { $features_types_model->add(); } $features_query = Features::find(); $pages = new Pagination(['totalCount' => $features_query->count()]); $pages->setPageSize(Features::FEATURES_PER_PAGE); $features_list = $features_query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); return $this->render('types', ['metrics_list' => FeaturesMetrics::find()->asArray()->all(), 'features_types_model' => $features_types_model, 'features_list' => $features_list, 'current_mode' => $current_mode, 'features_synonims' => FeaturesSynonims::getUnsorted(), 'pages' => $pages]); }
/** * Lists all Album models. * @return mixed */ public function actionIndex() { $query = Album::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('albumIndex', ['models' => $models, 'pages' => $pages]); // $dataProvider = new ActiveDataProvider([ // 'query' => Album::find(), // ]); // // return $this->render('index', [ // 'dataProvider' => $dataProvider, // ]); }
public function actionIndex() { $query = Topic::find()->joinWith('topicContent')->joinWith('user')->orderBy('topic_date_add DESC'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $page = 1; if (isset($_GET["page"])) { $page = $_GET["page"]; } $limit = 10; $offset = $limit * ($page - 1); $pageSize = ceil($countQuery->count() / $limit); $pages->setPageSize($pageSize); $models = $query->offset($offset)->limit($limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); }
/** * Lists all Song models. * @param $song_kingdom_id * @return mixed */ public function actionIndex($song_kingdom_id) { $query = Song::find()->andWhere(['created_by' => Yii::$app->getUser()->getId(), 'song_kingdom_id' => $song_kingdom_id]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('songIndex', ['models' => $models, 'pages' => $pages]); // $dataProvider = new ActiveDataProvider([ // 'query' => Song::find(), // ]); // // return $this->render('index', [ // 'dataProvider' => $dataProvider, // ]); }
public function actionCategory() { $category_id = Yii::$app->request->get('category'); if (is_null($category_id)) { return $this->actionIndex(); } $query = TblBlog::find()->where(['category_id' => $category_id]); $page = clone $query; $pages = new Pagination(['totalCount' => $query->count()]); $pages->setPageSize(5); $articles = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all(); foreach ($articles as $key => $value) { $articles[$key]['text'] = mb_substr($value['text'], 0, 100, 'UTF-8'); } $category = TblCategory::find()->where(['id' => $category_id])->asArray()->one(); return $this->render('category', ['articles' => $articles, 'category' => $category, 'pages' => $pages]); }
/** * Lists all Photo models. * @return mixed */ public function actionIndex($album_id) { $albumModel = Album::findOne($album_id); $query = Photo::find()->andWhere(['album_id' => $album_id]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('photoIndex', ['models' => $models, 'pages' => $pages, 'userCreadedBy' => User::find()->andWhere(['id' => $albumModel->created_by])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $albumModel->created_by])->asArray()->one()]); // $dataProvider = new ActiveDataProvider([ // 'query' => Photo::find(), // ]); // // return $this->render('index', [ // 'dataProvider' => $dataProvider, // ]); }
public function actionIndex() { $query = Users::find()->leftJoin('media', array('id' => 'user_id'))->where(['type' => 1, 'active' => 1]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); echo $pages; die; $page = 1; if (isset($_REQUEST["page"])) { $page = intVal($_REQUEST["page"]); } $limit = 12; $offset = $limit * ($page - 1); $pageSize = ceil($countQuery->count() / $limit); $pages->setPageSize($pageSize); $models = $query->offset($offset)->limit($limit)->all(); $city = City::find()->all(); return $this->render('index', ['models' => $models, 'pages' => $pages, 'city' => $city]); }
public function actionFind($propert = '', $price = '', $apartment = '') { $this->layout = 'sell'; $query = Advert::find(); $query->filterWhere(['like', 'address', $propert])->orFilterWhere(['like', 'description', $propert])->andFilterWhere(['type' => $apartment]); if ($price) { $prices = explode("-", $price); if (isset($prices[0]) && isset($prices[1])) { $query->andWhere(['between', 'price', $prices[0], $prices[1]]); } else { $query->andWhere(['>=', 'price', $prices[0]]); } } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $model = $query->offset($pages->offset)->limit($pages->limit)->all(); $request = \Yii::$app->request; return $this->render("find", ['model' => $model, 'pages' => $pages, 'request' => $request]); }
/** * Список заявок. * * @return string */ public function actionIndex() { /** @var \common\models\User $user */ $user = Yii::$app->getUser()->getIdentity(); $query = Lead::find()->where(['company_id' => $user->getCompanyId(), 'is_deleted' => false]); if ($selectedLandingId = Yii::$app->getSession()->get('selected_landing_id')) { $query->andWhere(['landing_id' => $selectedLandingId]); } if ($selectedLeadStatus = Yii::$app->getSession()->get('selected_lead_status')) { $query->andWhere(['status' => $selectedLeadStatus]); } $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(LeadHelper::SHOW_LEAD_PER_PAGE); $leads = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['lead_id' => SORT_DESC])->all(); $landingNames = (new LandingComponent())->getActiveLandingNamesByCompanyId($user->getCompanyId()); if (empty($landingNames)) { Yii::$app->getSession()->setFlash('warning', sprintf('Не возможно добавлять заявки, так как не было создано ни одной промо-страницы! <a href="%s">Добавить промо-страницу.</a>', Url::to('/landing/add'))); } return $this->render('index', ['user' => $user, 'leads' => $leads, 'pagination' => $pagination, 'landingNames' => $landingNames, 'selectedLandingId' => $selectedLandingId, 'selectedLeadStatus' => $selectedLeadStatus]); }
public static function getPagedRows($query, $config = []) { $db = isset($config['db']) ? $config['db'] : null; $cloneQuery = clone $query; $pager = new Pagination(['totalCount' => $cloneQuery->count('*', $db)]); if (isset($config['page'])) { $pager->setPage($config['page'], true); } if (isset($config['pageSize'])) { $pager->setPageSize($config['pageSize'], true); } $rows = $query->offset($pager->offset)->limit($pager->limit); if (isset($config['orderBy'])) { $rows = $rows->orderBy($config['orderBy']); } $rows = $rows->all($db); $rowsLable = isset($config['rows']) ? $config['rows'] : 'rows'; $pagerLable = isset($config['pager']) ? $config['pager'] : 'pager'; $ret = []; $ret[$rowsLable] = $rows; $ret[$pagerLable] = $pager; return $ret; }
public static function getPagedRows($queryModel, $config = []) { if (isset($_GET['page'])) { $config['urlWhere']['page'] = intval($_GET['page']); } if (isset($config['where']) && !empty($config['where'])) { $query = $queryModel->where($config['where']); } else { $query = $queryModel; } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'params' => isset($config['urlWhere']) ? $config['urlWhere'] : []]); if (isset($config['pageSize'])) { $pages->setPageSize($config['pageSize'], true); } $rows = $query->offset($pages->offset)->limit($pages->limit); if (isset($config['order'])) { $rows = $rows->orderBy($config['order']); } $rows = $rows->all(); $rowsLable = 'rows'; $pagesLable = 'pages'; if (isset($config['rows'])) { $rowsLable = $config['rows']; } if (isset($config['pages'])) { $pagesLable = $config['pages']; } $ret = []; $ret[$rowsLable] = $rows; $ret[$pagesLable] = $pages; return $ret; }
/** * 获取列表记录 * * @param array|string $condition 条件 * @param array $params 参数 * @param string $order 排序 * @param int $page 页码 * @param int $pageSize 每页数量 * @return array */ public static function getListByCondition($condition = '', $params = [], $order = null, $page = 1, $pageSize = 20) { $pagination = new Pagination(); $pagination->setPage($page); $pagination->setPageSize($pageSize); $pagination->totalCount = static::find()->innerJoinWith('menuUrl')->andWhere($condition, $params)->count(1); $list = static::find()->innerJoinWith('menuUrl')->andWhere($condition, $params)->offset($pagination->getOffset() - $pagination->getPageSize())->limit($pagination->getPageSize())->orderBy($order)->asArray()->all(); return ['paginationObj' => $pagination, 'pagination' => ['currentPage' => $page, 'pageSize' => $pageSize, 'pageCount' => $pagination->getPageCount(), 'totalCount' => $pagination->totalCount], 'list' => $list]; }
/** * 获取列表数据 * @param integer $login_uid * @param integer $pageSize * @param mixed $where * @param mixed $sort * @return [] */ public function getMyList($login_uid, $pageSize, $where, $sort = ['add_time' => SORT_DESC]) { $model_Message = new Message(); /** select * from message where msg_id in( select MAX(msg_id) from message GROUP BY from_uid ) */ $message = new Message(); $query = $message->find(); $query->select('max(`msg_id`)'); $query->where(['to_uid' => $login_uid]); $query->groupBy('from_uid'); $pagination = new Pagination(); $pagination->totalCount = $query->count(); $pagination->setPageSize($pageSize); $offset = $pagination->getOffset(); $limit = $pagination->getLimit(); $condition[0] = 'in'; $condition[1] = 'msg_id'; $condition[2] = $query; $query_all = $model_Message->find()->where($condition)->offset($offset)->limit($limit); // echo $query_all->createCommand()->getRawSql(); // exit(); // echo $query->createCommand()->getRawSql(); // exit; $a_models = $query_all->all(); if (isset($_GET[$pagination->pageParam]) && $pagination->pageCount < $_GET[$pagination->pageParam]) { $a_models = []; } $temp_data['models'] = $a_models; $temp_data['pagination'] = $pagination; return $temp_data; }
/** * sitemap * @return mixed */ public function actionSitemap() { /* header response */ Yii::$app->response->format = Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); /* begin */ $sitemaps = []; /* blog sitemap */ $query = Blog::find()->where(['status' => Blog::STATUS_PUBLISHED]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/blog/sitemap', 'page' => $i + 1]); } } /* page sitemap */ $query = PageData::find()->where(['status' => PageData::STATUS_ACTIVE]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/page/sitemap', 'page' => $i + 1]); } } /* load modules sitemap */ $modules = scandir(\Yii::$app->vendorPath . '/modernkernel'); foreach ($modules as $module) { if (!preg_match('/[\\.]+/', $module)) { $moduleName = str_ireplace('yii2-', '', $module); if (method_exists(Yii::$app->getModule($moduleName), 'sitemap')) { $sitemaps = array_merge($sitemaps, Yii::$app->getModule($moduleName)->sitemap()); } } } return $this->renderPartial('sitemap', ['sitemaps' => $sitemaps]); }
public static function getPagedRows($query, $config = []) { $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); if (isset($config['page'])) { $pages->setPage($config['page'], true); } if (isset($config['pageSize'])) { $pages->setPageSize($config['pageSize'], true); } $rows = $query->offset($pages->offset)->limit($pages->limit); if (isset($config['order'])) { $rows = $rows->orderBy($config['order']); } $rows = $rows->all(); $rowsLable = 'rows'; $pagesLable = 'pages'; if (isset($config['rows'])) { $rowsLable = $config['rows']; } if (isset($config['pages'])) { $pagesLable = $config['pages']; } $ret = []; $ret[$rowsLable] = $rows; $ret[$pagesLable] = $pages; return $ret; }
public function findAllWithPage($para = [], $obj = false) { self::paraProcess($para); if (empty($this->_relations)) { $feedback = !empty(self::$_params[XIIS_PARAMS_CONDITION]) ? parent::find()->select(self::$_params[XIIS_PARAMS_FIELDS])->where(self::$_params[XIIS_PARAMS_CONDITION])->orderBy(self::$_params[XIIS_PARAMS_ORDERBY]) : parent::find()->select(self::$_params[XIIS_PARAMS_FIELDS])->orderBy(self::$_params[XIIS_PARAMS_ORDERBY]); } else { $feedback = !empty(self::$_params[XIIS_PARAMS_CONDITION]) ? parent::find()->select(self::$_params[XIIS_PARAMS_FIELDS])->where(self::$_params[XIIS_PARAMS_CONDITION])->orderBy(self::$_params[XIIS_PARAMS_ORDERBY])->with($this->_relations) : parent::find()->select(self::$_params[XIIS_PARAMS_FIELDS])->orderBy(self::$_params[XIIS_PARAMS_ORDERBY])->with($this->_relations); } if ($feedback) { $countQuery = clone $feedback; $pages = new Pagination([XIIS_FEEDBACK_COUNT => $countQuery->count()]); $pages->setPage(self::$_params[XIIS_PARAMS_PAGE] - 1); $pages->setPageSize(self::$_params[XIIS_PARAMS_PAGESIZE]); if ($obj) { $models = $feedback->offset($pages->offset)->limit($pages->limit); } else { $models = $feedback->offset($pages->offset)->limit($pages->limit)->asArray(); } $commandQuery = clone $models; self::logRecord(['sql' => __FUNCTION__ . ' : ' . $commandQuery->createCommand()->getRawSql()]); $data[XIIS_FEEDBACK_DATA] = $models->all(); $data[XIIS_FEEDBACK_PAGER] = self::getPager($pages); if ($models) { return self::getResponse(EC_ARPLUS_READ_DATA_SUCCESS, $data); } else { return self::getResponse(EC_ARPLUS_READ_FAIL_NO_DATA); } } else { return self::getResponse(EC_ARPLUS_READ_FAIL_NO_DATA, $feedback); } }
public static function findAllWithPage($para = [], $obj = false) { self::paraProcess($para); $feedback = !empty(self::$_paraCondition) ? parent::find()->select(self::$_paraSelectFields)->where(self::$_paraCondition)->orderBy(self::$_paraOrderby) : parent::find()->select(self::$_paraSelectFields)->orderBy(self::$_paraOrderby); if ($feedback) { $countQuery = clone $feedback; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPage(self::$_paraPage - 1); $pages->setPageSize(self::$_paraLimit); if ($obj) { $models = $feedback->offset($pages->offset)->limit($pages->limit)->all(); } else { $models = $feedback->offset($pages->offset)->limit($pages->limit)->asArray()->all(); } $data['data'] = $models; if (self::$_pageLinkPagerOn) { $data['pager'] = LinkPager::widget(['pagination' => $pages]); } else { $data['pager'] = ['defaultPageSize' => $pages->defaultPageSize, 'forcePageParam' => $pages->forcePageParam, 'limit' => $pages->limit, 'links' => $pages->links, 'offset' => $pages->offset, 'page' => $pages->page, 'pageCount' => $pages->pageCount, 'pageParam' => $pages->pageParam, 'pageSize' => $pages->pageSize, 'pageSizeLimit' => $pages->pageSizeLimit, 'pageSizeParam' => $pages->pageSizeParam, 'params' => $pages->params, 'route' => $pages->route, 'totalCount' => $pages->totalCount, 'urlManager' => $pages->urlManager, 'validatePage' => $pages->validatePage]; } return self::getResponse(self::XII_READ_DATA_SUCCESS, $data); } else { return self::getResponse(self::XII_READ_FAIL_NO_DATA, $feedback); } }