Trait luya\traits\NextPrevModel
Available since version | 1.0.0 |
---|---|
Source Code | https://github.com/luyadev/luya/blob/master/core/traits/NextPrevModel.php |
Trait to us within ActiveRecords to get next and prev (previous) model records of the current ActiveRecord object model.
Public Methods
Method | Description | Defined By |
---|---|---|
getNext() | Get the next actrive record of the current id | luya\traits\NextPrevModel |
getPrev() | Get the previous record of a current id | luya\traits\NextPrevModel |
Method Details
Get the next actrive record of the current id
public yii\db\ActiveQuery getNext ( ) |
public function getNext()
{
return self::find()->where(['>', 'id', $this->id])->limit(1)->one();
}
Get the previous record of a current id
public yii\db\ActiveQuery getPrev ( ) |
public function getPrev()
{
return self::find()->where(['<', 'id', $this->id])->orderBy(['id' => SORT_DESC])->limit(1)->one();
}