Answer the question
In order to leave comments, you need to log in
Dynamic loading with saving the last id?
Good afternoon, at the moment dynamic loading by offset and limit is implemented
$offset = 0;
$limit = 8;
if (isset(Yii::$app->request->post()['offset'])) {
$offset = (int)Yii::$app->request->post()['offset'];
}
$query = Product::findNewest($audience_rec ? $audience_rec->id : null);
$query->limit($limit + 1);
$query->offset($offset);
Answer the question
In order to leave comments, you need to log in
It is far from a fact that everything in your store will be sorted by ID. and you need to solve it somehow.
In the simplest version, for example, I currently have it as a stub like this:
$query = Model::find()
->andWhere('id<:last_id',['last_id'=>$last_id])
->orderBy( 'id desc')
->limit(20)
;
In the same view, we render the block and if there are 20 records, then we insert a button to load other records.
Note that sorting in this case should be by id.
There is a more elegant solution for dynamic loading, but for the case if you use a DataProvider
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question