简体   繁体   中英

Yii using ActiveRecord

In my Yii application I have the model:

class Article extends ActiveRecord
{
public static function tableName()
{
    return '{{article}}';
}


public static function getLatestArticles()
{
    return parent::find()->where( 'TO_DAYS(NOW()) - TO_DAYS(published) <= 7 
                        AND ISNULL(arch)')
                       ->orderBy(
                           ['DAYOFWEEK(published)' => SORT_DESC,
                            'rubric' => SORT_ASC,
                           ])->all();
}

public function getArticlerubric()
{
    return $this->hasOne(Rubric::class,['id' => 'rubric']);
}

What is the correct way to use the getLatestArticles() function : parent::find(), self::find() or static::find() ?

static::find() would probably be the best bet, but self::find() should do the job.

Otherwise it's Article::find()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM