Answer the question
In order to leave comments, you need to log in
Yii2 how to disable pagination or increase the limit?
Pagination is a must. Sometimes. Not everyone.
I can't figure out how to turn it off. The controller code is the simplest from the documentation
class RestActiveController extends ActiveController
{
public $serializer = [
'class' => 'yii\rest\Serializer',
'collectionEnvelope' => 'items',
];
}
Answer the question
In order to leave comments, you need to log in
You can set the page size:
/goods?per-page=1000
When Query /goods
Runs yii\rest\IndexAction
, which returns
ActiveDataProvider(['query' => $modelClass::find()])
$pageParam = 'page'
$pageSizeParam = 'per-page'
$pageSizeLimit = [1, 50]
And the default yii\data\Pagination
one tries to take the parameters from $request->getQueryParams().
$pageSizeLimit = [1, 1000]
Googling your question, I immediately found the answer.
public function actionIndex()
{
//$posts = Post::find()->all();
$query = Post::find();
$pages = new Pagination(['totalCount' => $query->count()]);
$posts = $query->offset($pages->offset)
->limit($pages->limit)
->all();
return $this->render('index', compact('posts', 'pages'));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question