Yii2不起作用,错误获取未知属性:common \ models \ Articles :: id

时间:2018-11-21 10:34:43

标签: php yii yii2

请帮助我。该网站的开头出现错误

  

未知属性– yii \ base \ UnknownPropertyException获取未知   属性:common \ models \ Articles :: id

我不知道该怎么办

common \ models \ articles.php

public function beforeSave($insert)
{
    if (parent::beforeSave($insert)) {
        if(empty($this->date) or $this->date == '0000-00-00'){
            $this->date = date("j.n.Y");
        }
        if($this->cat_id !== 11){
            if($this->online == 1){
                $this->online_text = "Да";
            }else{
                $this->online_text = "Нет";
            }

            if(!empty($this->author_link) and $this->author_link != 9){
                $user = User::findOne($this->author_link);
                $this->author = $user['username']." ".$user['lastname'];
            }
        }
        if(!empty($this->time)){
            $time = $this->time;
            $time = explode(':',$time);
            $h = $time[0];
            $m = $time[1];
            $s = 0;
        }else{
            $h = 0;
            $m = 0;
            $s = 0;
        }

        if(!empty($this->date)){
            $date = $this->date;
            $date = explode('.',$date);
            $d = $date[0];
            $mon = $date[1];
            $y = $date[2];
            $this->orders = mktime($h,$m,$s,$mon,$d,$y);
        }


        return true;
    }
    return false;
}
public static function tableName()
{
    return 'Articles';
}

@前端模块\控制器

public function actionIndex($id=null)
{
    $query = articles::find()->where(['online' => 1]);
    $count = $query->count();
    $pagination = new Pagination(['totalCount' => $count, 'pageSize'=>6]);
    $news = $query->offset($pagination->offset)
        ->limit($pagination->limit)
        ->orderBy('id DESC')
        ->all();

    return $this->render('index',[
        'arts'=>$news,
        'pagination' => $pagination
        ]);
}

@frontviews \ articles

<a href="/article/<?echo $art['id']."-".$art['preview'].".html";?>" class="main-page__news__link js-views-link"></a>

0 个答案:

没有答案