diimmonn / yii2-widget-next-button
此包的最新版本(v1.0.0)没有提供许可证信息。
小部件渲染带有下一按钮的包装容器
v1.0.0
2015-02-23 12:26 UTC
This package is not auto-updated.
Last update: 2024-09-28 16:51:48 UTC
README
小部件渲染带有下一按钮的包装容器。
安装
使用 composer 安装
$ php composer.phar require diiimonn/yii2-widget-next-button "dev-master"
或添加
"diiimonn/yii2-widget-next-button": "dev-master"
到您的 composer.json 文件的 require 部分中。
用法
控制器
... use yii\data\Pagination; ... class SiteController extends Controller { ... public function actionIndex($id) { ... $query = MyModel::find(); $queryCount = clone $query; $pagination = new Pagination([ 'totalCount' => $queryCount->count(), 'pageSize' => 10, 'page' => 0, ]); $isNext = $pagination->getPageCount() > 1; $query->offset($pagination->offset); $query->limit($pagination->limit); $models = $query->all(); ... return $this->render('index', [ ... 'models' => $models, 'isNext' => $isNext, ]); } ... public function actionNext($id, $page = 0) { Yii::$app->response->format = 'json'; $json = new \stdClass(); $query = MyModel::find(); $queryCount = clone $query; $pagination = new Pagination([ 'totalCount' => $queryCount->count(), 'pageSize' => 10, 'page' => $page, ]); $nextPage = $page + 1; $json->page = $pagination->getPageCount() > $nextPage ? $nextPage : 0; $query->offset($pagination->offset); $query->limit($pagination->limit); $models = $query->all(); ... $json->html = $this->renderPartial('_items', [ ... 'models' => $models, ]); return $json; } ... }
视图结构
├── site
│ ├── index.php
│ ├── _items.php
│ ├── ...
视图 index.php
... use diiimonn\widgets\NextButton; use yii\helpers\Url; ... <?php $nextButton = NextButton::begin([ 'buttonContent' => Yii::t('app', 'Show next ...'), 'buttonOptions' => [/* button tag options */], 'isNext' => $isNext, 'scriptOptions' => [ 'ajax' => [ 'url' => Url::toRoute(['next', /* other params */]), // Url for ajax request to actionNext in SiteController. Required parameter ], ], 'options' => [/* widget tag options */], 'containerOptions' => [/* container tag for items options */], 'buttonContainerOptions' => [], 'buttonBlockOptions' => [], // for example ['class' => 'row'] 'buttonWrapOptions' => [], // for example ['class' => 'col-md-6 col-md-offset-3'] ]) ?> <?= $this->render('_items', [ ... 'models' => $models, ]) ?> <?php $nextButton::end() ?> ...