Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii使用ActiveRecord_Php_Yii2 - Fatal编程技术网

Php Yii使用ActiveRecord

Php Yii使用ActiveRecord,php,yii2,Php,Yii2,在我的Yii应用程序中,我有以下模型: 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

在我的Yii应用程序中,我有以下模型:

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']);
}
类文章扩展了ActiveRecord
{
公共静态函数tableName()
{
返回“{article}}”;
}
公共静态函数getLatestArticles()
{
return parent::find()->where('TO_DAYS(NOW())-TO_DAYS(published)static::find()可能是最好的选择,但是self::find()应该完成这项工作


否则就是Article::find()

你所说的“正确的方式”是什么意思?你知道不同的含义吗?它们在你的上下文中重要吗?是的,我理解父母、自我和静态的不同含义。此外,我已经试过了所有的方法,所有的变体都有效。所以我不知道使用哪种变体。