vivre-tech/rest-grid For Yii2: This extension provides the ability like GridView but for REST.

  1. Installation
  2. Usage
  3. Response
  4. Unit Testing

This extension provides the ability like GridView but for REST.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist vivre-tech/rest-grid

or add

"vivre-tech/rest-grid": "*"

to the require section of your composer.json.

Usage

Example: `php $arrayRows = []; foreach(range(1, 100) as $item) {

$arrayRows[] = [
    'id' => $item,
    'name' => 'Product ' . $item,
    'price' => 100 + $item,
    'created_at' => date('Y-m-d H:i:s')
];

}

$dataProvider = new \yii\data\ArrayDataProvider([

'allModels' => $arrayRows,
'pagination' => [
    'pageSize' => 5,
],

]);

$grid = new \vivretech\rest\grid\Grid([

'dataProvider' => $dataProvider,
'columns' => [
    [
        'attribute' => 'id'
    ],
    [
        'attribute' => 'name'
    ],
    [
        'attribute' => 'price'
    ],
    [
        'attribute' => 'created_at'
    ]
]

]);

return $grid->run(); `

Response

{
    "metadata": {
        "id": "aa899d9e6e420821e20f04ea857e0c2d_0",
        "caption": null,
        "description": null,
        "options": [],
        "header": {
            "show": true
        },
        "filters": {
            "show": true
        },
        "footer": {
            "show": false
        },
        "request_params": {
            "pager": {
                "param": "page",
                "size": "per-page"
            },
            "sorter": {
                "param": "sort",
                "separator": ",",
                "multi_sort": false
            }
        }
    },
    "pager": {
        "results": {
            "total": 1212,
            "per_page": 5
        },
        "pages": {
            "total": 243,
            "current": 1
        }
    },
    "columns": [
        {
            "label": "Id",
            "attribute": "id",
            "description": null,
            "options": [],
            "sortable": true,
            "filterable": false,
            "header": {
                "value": [],
                "options": []
            },
            "filter": {
                "selected": null,
                "items": [],
                "options": []
            },
            "footer": {
                "value": [],
                "options": []
            }
        },
        {
            "label": "Name",
            "attribute": "name",
            "description": null,
            "options": [],
            "sortable": true,
            "filterable": false,
            "header": {
                "value": [],
                "options": []
            },
            "filter": {
                "selected": null,
                "items": [],
                "options": []
            },
            "footer": {
                "value": [],
                "options": []
            }
        },
        {
            "label": "Price",
            "attribute": "price",
            "description": null,
            "options": [],
            "sortable": true,
            "filterable": false,
            "header": {
                "value": [],
                "options": []
            },
            "filter": {
                "selected": null,
                "items": [],
                "options": []
            },
            "footer": {
                "value": [],
                "options": []
            }
        },
        {
            "label": "Created At",
            "attribute": "created_at",
            "description": null,
            "options": [],
            "sortable": true,
            "filterable": false,
            "header": {
                "value": [],
                "options": []
            },
            "filter": {
                "selected": null,
                "items": [],
                "options": []
            },
            "footer": {
                "value": [],
                "options": []
            }
        }
    ],
    "items": [
        {
            "id": 1,
            "name": "Product 1",
            "price": 101,
            "created_at": "2018-04-02 17:54:52"
        },
        {
            "id": 2,
            "name": "Product 2",
            "price": 102,
            "created_at": "2018-04-02 17:54:52"
        },
        {
            "id": 3,
            "name": "Product 3",
            "price": 103,
            "created_at": "2018-04-02 17:54:52"
        },
        {
            "id": 4,
            "name": "Product 4",
            "price": 104,
            "created_at": "2018-04-02 17:54:52"
        },
        {
            "id": 5,
            "name": "Product 5",
            "price": 105,
            "created_at": "2018-04-02 17:54:52"
        }
    ]
}

Unit Testing

If you run the following command: composer install in a dev environment then you will find phpunit in /vendor/bin/phpunit.

In case phpunit in not installed via command composer install, just fallow next steps:

  1. run in console/terminal brew install phpunit

To test, in the root of the project, base on how phpunit is installed you will have two choices to run:

  1. installed via command composer install you will have to execute in console/terminal: vendor/bin/phpunit
  2. installed via brew you will have to execute in console/terminal: phpunit
0 0
1 follower
8 979 downloads
Yii Version: 2.0
License: MIT
Category: Web Service
Developed by: microThread
Created on: Mar 26, 2018
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions