Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2: How do change Pagination-Per-Page into RESTful Web Service API?

Tags:

I am developing an application using AngularJS for the frontend and Yii2 for the backend.

The frontend requires a comprehensive array of all users.

In the documentation of Yii2, http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html I can read the result divided by X-Pagination-Per-Page: 20

How do I set X-Pagination-Per-Page: ALL ??

like image 430
Janka Avatar asked Dec 11 '14 11:12

Janka


People also ask

How to setup pagination style in yii2?

So setup style of pagination in Yii2 is very easy. Its same as in Yii. Thats it. You can use pager parameter in ListView and in GridView as well. Now you can write css of paginationClassName according to your requirement.

What is API pagination and how does it work?

API pagination is a key strategy for making sure your APIs run smoothly and effectively. But what is API pagination? How can API pagination help your APIs function at peak performance? We’re going to tell you, in our complete guide to API pagination. To make sure we’re on the same page, let’s start by looking at what pagination is.

What are the benefits of the Yii REST framework?

The Benefits of the Yii REST Framework. The Yii Framework provides broad support and detailed documentation for building APIs. Here are some of the built-in capabilities when building APIs: Quick prototyping with support for common APIs for Active Record.

How do I build REST APIs in Yii?

Building REST APIs in Yii is actually fairly straightforward. You can leverage the existing MVC framework, but you're creating a distinct access point that you intend to be accessed by different kinds of services (not website visitors). The Yii Framework provides broad support and detailed documentation for building APIs.


1 Answers

If you are using yii\rest\ActiveController as parent from your controller, you need to override the action index in your controller.

This is my code

class StnkController extends ActiveController{     public $modelClass = "common\models\Stnk";      public function actions(){         $actions = parent::actions();         unset($actions['index']);         return $actions;     }      public function actionIndex(){         $activeData = new ActiveDataProvider([             'query' => Stnk::find(),             'pagination' => [                 'defaultPageSize' => 2,             ],         ]);         return $activeData;     } } 
like image 160
Wilianto Indrawan Avatar answered Sep 17 '22 14:09

Wilianto Indrawan