我需要在 Yii 框架的数据库中记录 next 和 previous id 来制作导航按钮 next 和 back 吗?
最佳答案
我在 Yii2 的模型中添加了以下函数:
public function getNext() {
$next = $this->find()->where(['>', 'id', $this->id])->one();
return $next;
}
public function getPrev() {
$prev = $this->find()->where(['<', 'id', $this->id])->orderBy('id desc')->one();
return $prev;
}
关于php - 在 Yii 的数据库中获取下一个和上一个 id 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8872101/