PHPackages                             diiimonn/yii2-widget-next-button - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. diiimonn/yii2-widget-next-button

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

diiimonn/yii2-widget-next-button
================================

Widget render wrap container for a list with next button

v1.0.0(11y ago)071PHP

Since Feb 23Pushed 11y ago1 watchersCompare

[ Source](https://github.com/diiimonn/yii2-widget-next-button)[ Packagist](https://packagist.org/packages/diiimonn/yii2-widget-next-button)[ Docs](https://github.com/diiimonn/yii2-widget-next-button)[ RSS](/packages/diiimonn-yii2-widget-next-button/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

yii2-widget-next-button
=======================

[](#yii2-widget-next-button)

Widget render wrap container for a list with next button.

Installation
------------

[](#installation)

To install with composer:

```
$ php composer.phar require diiimonn/yii2-widget-next-button "dev-master"

```

or add

```
"diiimonn/yii2-widget-next-button": "dev-master"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### controller:

[](#controller)

```
...
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;
    }

    ...
}
```

### structure views:

[](#structure-views)

```
├── site
│   ├── index.php
│   ├── _items.php
│   ├── ...

```

### view index.php

[](#view-indexphp)

```
...
use diiimonn\widgets\NextButton;
use yii\helpers\Url;

...
