V
V
Vitaly Liber2015-04-16 15:31:38
Yii
Vitaly Liber, 2015-04-16 15:31:38

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>

How to make buttons on the created pages that would allow you to go further or back between the created pages?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Semenko, 2015-04-16
@VitalyLiber

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 question

Ask a Question

731 491 924 answers to any question