Trait luya\traits\NextPrevModel

Available since version1.0.0

Trait to us within ActiveRecords to get next and prev (previous) model records of the current ActiveRecord object model.

Public Methods

Hide inherited 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

Hide inherited methods

getNext() public method

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();
}

            
getPrev() public method

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();
}