无法在yii2 rest或activeDataProvider中设置pageSize限制

时间:2017-02-08 16:26:59

标签: rest yii pagination yii2 yii-rest

我无法在rest app中设置ActiveDataProvider(分页)pageSize的值 为了更改每页中的项目。 这是我在控制器中的示例代码

class EndpointController extends ActiveController
{
public $modelClass = 'common\models\Endpoint';
//     public $serializer = [
//         'class' => 'yii\rest\Serializer',
//         'collectionEnvelope' => 'items',
    // //         'metaEnvelope' => false
//     ];
public function init()
{
    parent::init();
    \Yii::$app->user->enableSession = false;
    \Yii::$app->user->loginUrl = null;
}
public function behaviors()
{
    $behaviors = parent::behaviors();
    $behaviors['authenticator'] = [
        'class' => QueryParamAuth::className(),
        'tokenParam' => 'access_token',
    ];
    return $behaviors;
}
protected function verbs()
{
    $verbs = parent::verbs();
    unset($verbs['update'], $verbs['create'], $verbs['delete'],         $verbs['view'], $verbs['index'][1]);
//         $verbs['index'][] = 'POST';
    return $verbs;
}

public function actions()
{
    $actions = parent::actions();
    unset($actions['update'], $actions['create'], $actions['delete'], $actions['view'], $actions['options']);
    return $actions;
}
public function prepareDataProvider()
{
//         $activData = new ActiveDataProvider([
//             'query' => Endpoint::find(),
//             'pagination' => [
//                 'pageSize' => 2,
//             ]
//         ]);
//         return $activData;
}

public function actionIndex()
{
//         $activData = new ActiveDataProvider([
//             'query' => Endpoint::find(),
//             'pagination' => [
//                 'pageSize' => 2,
//             ]
//         ]);
    //         return $activData;
}    
}

我的模型有基本模板,我之前在互联网上测试了所有解决方案,但我没有效果

1 个答案:

答案 0 :(得分:0)

我通过回答JamesLeon找到了解决方案 评论github