Answer the question
In order to leave comments, you need to log in
How to create a working next and back button in Yii2 on a page rendered from id?
Created a set of links based on the ListView and the following code.
<a href="<?= Url::to(['site/view', 'id' => $model->id]) ?>">Подробнее</a>
Answer the question
In order to leave comments, you need to log in
class Model extends yii\Db\ActiveRecord {
public function getPrev() {
return self::find()->where(['<', 'id', $this->id])->orderBy('id DESC')->one();
}
public function getNext() {
return self::find()->where(['>', 'id', $this->id])->orderBy('id ASC')->one();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question