Yii 1.0 升级 Yii 2.0

//命名空间
use appcomponentsHttpException;

model废除方法relations(),scopes()

    Yii::app()
修改成
    Yii::$app
    
    $this->render('/' . $this->id, array('orders' => $orderSearch))
修改成
    return $this->render('/' . $this->id, array('orders' => $orderSearch))

    throw new THttpException('抱歉,您没有权限修改!');
修改成
    throw new HttpException('抱歉,您没有权限修改!');

    Campaign::model()->getAll();
修改成
    appmodelsCampaign::find()->all();

    Cjson::encode($array);
修改成
    yiihelpersJson::encode($array);

    public function beforeSave(){
        parent::beforeSave();
    }
修改成
    public function beforeSave($insert){
        parent::beforeSave($insert);
    }

    public function afterSave()
    {
        parent::afterSave();
    }
修改成
    public function afterSave($insert, $changedAttributes)
    {
        parent::afterSave($insert, $changedAttributes);
        if($insert) {  
            //这里是新增数据  
        } else {  
            //这里是更新数据  
        }
    }
    
    public function tableName()
    {
        return 'v_report_ads';
    }
修改成
    public static function tableName()
    {
        return 'v_report_ads';
    }
    
    
    $criteria = new CDbCriteria;
    ....
    $models = Adgroup::model()->findAll($criteria);
修改成
    $query = appmodelsAdgroup::find();
    ...
    $models = $query->all();
    
原文地址:https://www.cnblogs.com/qq917937712/p/5688614.html