本文整理汇总了PHP中yii\data\ActiveDataProvider::getPagination方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveDataProvider::getPagination方法的具体用法?PHP ActiveDataProvider::getPagination怎么用?PHP ActiveDataProvider::getPagination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\data\ActiveDataProvider
的用法示例。
在下文中一共展示了ActiveDataProvider::getPagination方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setFormatters
private function setFormatters()
{
$currentPage = $this->dataProvider->getPagination()->getPage() + 1;
$response = Yii::$app->response;
$response->formatters[UrlsetResponseFormatter::FORMAT_URLSET] = new UrlsetResponseFormatter(['gzip' => $this->gzip, 'gzipFilename' => 'sitemap.' . $currentPage . '.xml.gz']);
$response->format = UrlsetResponseFormatter::FORMAT_URLSET;
}
示例2: setFormatters
/**
* set Action Response Formatter
*/
protected function setFormatters()
{
$currentPage = $this->dataProvider->getPagination()->getPage() + 1;
$response = Yii::$app->response;
$formatter = new UrlsetResponseFormatter(['gzip' => $this->gzip, 'gzipFilename' => 'sitemap.' . $currentPage . '.xml.gz']);
$xmlns = $this->xmlns;
if (null === $xmlns) {
$xmlns = call_user_func([$this->urlClass, 'getXmlns']);
}
$formatter->addXmlns($xmlns);
$response->formatters[UrlsetResponseFormatter::FORMAT_URLSET] = $formatter;
$response->format = UrlsetResponseFormatter::FORMAT_URLSET;
}
示例3: actionList
public function actionList($event_id)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$dp = new ActiveDataProvider();
$dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]);
$dp->pagination->pageSize = 6;
return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()];
}
示例4: actionIndex
/**
* Lists all MyClick models.
* @return mixed
*/
public function actionIndex()
{
$query = (new \yii\db\Query())->select('article.*')->from('my_click')->where(['user_id' => \Yii::$app->user->id])->orderBy('my_click.id DESC');
$click_query = $query->limit(50)->join('LEFT JOIN', 'article', 'article.id = my_click.article_id');
$provide = new ActiveDataProvider(['query' => $click_query, 'pagination' => ['pageSize' => 10]]);
$provide->prepare();
$pagination = $provide->getPagination();
return $this->render('index', ['data' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]);
}
示例5: actionRead
public function actionRead($id)
{
$taxonomy = Taxonomy::findByIdOrSlug($id);
$children = $taxonomy->children()->all();
$ids = ArrayHelper::getColumn($children, "taxonomy_id");
array_unshift($ids, $taxonomy->getPrimaryKey());
$dataProvider = new ActiveDataProvider(['query' => TaxonomyIndex::find()->select(['entity', 'entity_id'])->distinct()->where(["taxonomy_id" => $ids])->orderBy(['taxonomy_index_id' => SORT_DESC]), 'pagination' => ['pageSize' => 15]]);
list($title, $desc, $keys) = $taxonomy->getMetaData();
$this->getView()->setMetaData($title, $desc, $keys);
return $this->render('view', ['taxonomyIndexs' => $dataProvider->getModels(), "pagination" => $dataProvider->getPagination(), "taxonomy" => $taxonomy]);
}
示例6: actionIndex
public function actionIndex()
{
if (\Yii::$app->user->isGuest) {
$this->redirect(['user/sign-in/login']);
}
$article = (new Query())->from('article')->all();
$query = Article::find();
$provide = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC, 'title' => 'simon']]]);
$provide->prepare();
$pagination = $provide->getPagination();
return $this->render('index', ['article' => $provide->getModels(), 'pageCount' => $pagination->pageCount, 'page' => $pagination->page, 'links' => $pagination->getLinks()]);
}
示例7: run
/**
*
* @return type
*/
public function run()
{
$data = new ActiveDataProvider(['query' => $this->query, 'pagination' => ['class' => Pagination::class, 'pageSize' => $this->recordOnPage]]);
$data->query->addOrderBy($this->sort);
if (Yii::$app->getRequest()->isAjax) {
Yii::$app->getResponse()->format = Response::FORMAT_JSON;
return $this->controller->renderPartial($this->view, ['model' => $data->getModels()]);
} else {
$this->controller->layout = $this->layout;
return $this->controller->render($this->view, ['model' => $data->getModels(), 'pages' => $data->getPagination()]);
}
}
示例8: search
/**
* Search by request criteria.
*
* @param array|null Filter params.
* @return ActiveDataProvider Data provider.
*/
public function search($params)
{
$query = User::find()->with('roles');
$dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['date_create' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]);
$dataProvider->getPagination()->setPageSize(Yii::$app->request->get('pageSize'), true);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(['ip' => !empty($this->ip) ? ip2long($this->ip) : null, 'status' => $this->status, 'role' => $this->role, 'DATE(date_create)' => $this->date_create]);
$query->andFilterWhere(['like', 'user.username', $this->username]);
$query->andFilterWhere(['like', 'user.email', $this->email]);
return $dataProvider;
}
示例9: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Country::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
//手动添加的分页
$dataProvider->getPagination()->pageSize = 5;
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['population' => $this->population]);
$query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
示例10: actionView
public function actionView($slug)
{
$album = Gallery::cat($slug);
if (!$album) {
throw new \yii\web\NotFoundHttpException('无照片.');
}
// 评论列表
$commentDataProvider = new ActiveDataProvider(['query' => Comment::find()->andWhere(['article_id' => $album->model->category_id, 'parent_id' => 0, 'comment_type' => 'gallery']), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
//评论数
$commentNum = Comment::find()->andWhere(['article_id' => $slug, 'parent_id' => 0, 'comment_type' => 'gallery'])->count(1);
$commentModels = $commentDataProvider->getModels();
$pages = $commentDataProvider->getPagination();
// 评论框
$commentModel = new Comment();
return $this->render('view', ['album' => $album, 'photos' => $album->photos(['pagination' => ['pageSize' => 10]]), 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'commentDataProvider' => $commentDataProvider, 'commentNum' => $commentNum]);
}
示例11: actionView
/**
* Displays a single Estimate model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$model = $this->findModel($id);
$dataProvider = new ActiveDataProvider(['query' => $model->getEntries()->with('product.supplier')]);
$dataProvider->sort = ['defaultOrder' => ['rank' => SORT_ASC]];
// Set last page as default
$pagination = $dataProvider->getPagination();
$page = Yii::$app->request->getQueryParam($pagination->pageParam);
if (!$page) {
$pagination->totalCount = $dataProvider->getTotalCount();
$page = $pagination->getPageCount() - 1;
$pagination->setPage($page);
}
if (Yii::$app->request->post('hasEditable')) {
$id = Yii::$app->request->post('editableKey');
$entry = EstimateEntry::findOne($id);
$out = Json::encode(['output' => '', 'message' => '']);
$post = [];
$posted = current($_POST['EstimateEntry']);
$post['EstimateEntry'] = $posted;
if ($entry->load($post)) {
if ($entry->save()) {
$entry->estimate->doEstimate();
}
$output = '';
if (isset($posted['status'])) {
$output = $entry->statusLabel;
}
$out = Json::encode(['output' => $output, 'message' => $entry->getErrors()]);
}
// return ajax json encoded response and exit
echo $out;
return;
}
return $this->render('view', ['model' => $model, 'dataProvider' => $dataProvider]);
}
示例12: actionTopic
/**
* Show topic with posts
* @param $id integer topic_id
* @param $nav string post-id or "last"
*/
public function actionTopic($id = null, $nav = null, $postId = null)
{
$id = $id ?: \Yii::$app->request->get('id');
$topic = BbiiTopic::findOne($id);
if ($topic === null) {
throw new HttpException(404, Yii::t('BbiiModule.bbii', 'The requested topic does not exist.'));
}
$forum = BbiiForum::findOne($topic->forum_id);
if (\Yii::$app->user->isGuest && $forum->public == 0) {
throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.'));
}
if ($forum->membergroup_id != 0) {
if (\Yii::$app->user->isGuest) {
throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.'));
} elseif (!$this->isModerator()) {
$groupId = BbiiMember::find(\Yii::$app->user->identity->id)->one()->group_id;
if ($forum->membergroup_id != $groupId) {
throw new HttpException(403, Yii::t('BbiiModule.bbii', 'You have no permission to read requested topic.'));
}
}
}
/* $dataProvider = new ActiveDataProvider(
'BbiiPost', array(
'criteria' => array(
'condition' => 'approved = 1 and topic_id = ' . $topic->id,
'order' => 't.id',
'with' => array('poster'),
),
'pagination' => array(
'pageSize' => $this->module->postsPerPage,
),
)); */
$dataProvider = new ActiveDataProvider(['query' => BbiiPost::find()->where('approved = 1 and topic_id = ' . $topic->id)->orderBy('id ASC')]);
// @todo Poll not enabled for inital release - DJE : 2015-05-27
// Determine poll
/*
$criteria = new CDbCriteria;
$criteria->condition = 'post_id = ' . $topic->first_post_id;
$this->poll = BbiiPoll::find()->find($criteria);
if ($this->poll !== null) {
$this->choiceProvider = new ActiveDataProvider('BbiiChoice', array(
'criteria' => array(
'condition' => 'poll_id = ' . $this->poll->id,
'order' => 'sort',
),
'pagination' => false,
));
// Determine whether user has voted
if (\Yii::$app->user->isGuest) {
$this->voted = true; // A guest may not vote and sees the result immediately
} else {
$criteria->condition = 'poll_id = ' . $this->poll->id . ' and user_id = ' . \Yii::$app->user->identity->id ;
$this->voted = BbiiVote::find()->exists($criteria);
}
// Determine wheter the poll has expired
if (!$this->voted && isset($this->poll->expire_date) && $this->poll->expire_date < date('Y-m-d')) {
$this->voted = true;
}
}
*/
// Navigate to a post in a topic
if (isset($nav)) {
$cPage = $dataProvider->getPagination();
if (is_numeric($nav)) {
$criteria->condition = 'topic_id = ' . $topic->id . ' and id < = ' . $nav . ' and approved = 1';
$count = BbiiPost::find()->count($criteria);
$page = ceil($count / $cPage->pageSize);
$post = $nav;
} else {
$page = ceil($dataProvider->totalItemCount / $cPage->pageSize);
$post = $topic->last_post_id;
}
if (\Yii::$app->user->hasFlash('moderation')) {
\Yii::$app->session->addFlash('moderation', \Yii::$app->user->getFlash('moderation'), true);
}
return \Yii::$app->response->redirect(array('forum/forum/topic', 'id' => $id, 'BbiiPost_page' => $page, 'postId' => $post));
}
// Increase topic views
$topic->updateCounters(array('num_views' => 1));
// Register the last visit of a topic
if (!\Yii::$app->user->isGuest) {
$object = new BbiiTopicsRead();
$model = BbiiTopicRead::find()->where(['user_id' => \Yii::$app->user->identity->id])->one();
if (empty($model->data)) {
$model = new BbiiTopicRead();
$model->user_id = \Yii::$app->user->identity->id;
} else {
$object->unserialize($model->data);
}
$object->setRead($topic->id, $topic->last_post_id);
if ($object->follows($topic->id)) {
$object->setFollow($topic->id, $topic->last_post_id);
}
$model->setAttribute('data', $object->serialize());
if (!$model->validate() || !$model->save()) {
//.........这里部分代码省略.........
示例13: jgridBooks
/**
*
* @param array $data [page, limit, sort_column, sort_order, filters=json]
* @return multitype:multitype:Ambigous <NULL> multitype:unknown string |\stdClass
*/
public static function jgridBooks(array $data)
{
$query = self::jqgridPepareQuery($data);
$data['limit'] = empty($data['limit']) || $data['limit'] <= 0 || $data['limit'] > 30 ? 10 : $data['limit'];
$data['page'] = empty($data['page']) || $data['page'] <= 0 ? 1 : $data['page'];
$provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $data['limit'], 'page' => $data['page'] - 1]]);
$books = $provider->getModels();
$to_array = function ($obj_arr, $query) {
$ar = [];
foreach ($obj_arr as $o) {
/* @var $o Books */
$book = [];
$attr = $o->getAttributes($o->fields());
//jgrid required no assoc array same order
foreach ($query->select as $col) {
if ($col == 'created_date') {
$book[] = \Yii::$app->formatter->asDate($attr[$col], 'php:d-m-Y');
} else {
$book[] = $attr[$col];
}
}
$ar[] = ['id' => $attr['book_guid'], 'cell' => $book];
}
return $ar;
};
return self::jqgridPrepareResponse($provider->getPagination()->getPage(), $provider->getPagination()->getPageCount(), $provider->getTotalCount(), $to_array($books, $query));
}
示例14: initDataProvider
public function initDataProvider()
{
$this->search = new Search(CmsContentElement::className());
$this->dataProvider = $this->search->getDataProvider();
if ($this->enabledPaging == Cms::BOOL_Y) {
$this->dataProvider->getPagination()->defaultPageSize = $this->pageSize;
$this->dataProvider->getPagination()->pageParam = $this->pageParamName;
$this->dataProvider->getPagination()->pageSizeLimit = [(int) $this->pageSizeLimitMin, (int) $this->pageSizeLimitMax];
} else {
$this->dataProvider->pagination = false;
}
if ($this->orderBy) {
$this->dataProvider->getSort()->defaultOrder = [$this->orderBy => (int) $this->order];
}
return $this;
}
示例15: actionTestl
public function actionTestl()
{
echo "sss";
$dataProvider = new ActiveDataProvider(['query' => Appcomments::find()]);
//$dataProvider->keys;
//$dataProvider->models;
/*$dataProvider->setPagination(false);
$mymodel=$dataProvider->models;
foreach ($mymodel as $model){
echo $model['appid'];
}*/
$pagination = $dataProvider->getPagination();
var_dump($pagination->page);
$count = 0;
while ($categories = $dataProvider->models) {
/*foreach ($categories as $model) {
$model['appid']=0;
}*/
//echo $pagination->page=1+$count;
$count++;
$dataProvider->setPagination($count);
}
//$mymodel[4]['kind']="bbbbbb";
//$dataProvider->setModels($mymodel);
//var_dump($dataProvider->models[4]['kind']);
//echo $dataProvider->models;
}