yii2-调用未定义的方法yii \ base \ ErrorException :: getSeverity()

时间:2018-03-19 06:32:28

标签: php excel exception yii2

我正在研究yii2。我发布记录作为从excel文件批量导入。我有一个主模型Sims,其中放置了所有记录。向用户发出imsi时,主记录中的issued_to字段将更新。 issued_to的更新在逐个发布imsi时正在进行。但是当我通过excel文件发布它时,它会更新issued_to字段但是在插入所有记录后它会给我以下错误

  

处理其他错误时出错:

Error: Call to undefined method yii\base\ErrorException::getSeverity() in E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\ErrorHandler.php:287
Stack trace:
#0 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\ErrorHandler.php(107): yii\base\ErrorHandler->logException(Object(yii\base\ErrorException))
> #1 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\ErrorException))
#2 {main}
> Previous exception:
yii\base\ErrorException: Creating default object from empty value in E:\xampp\htdocs\inventory-web\common\models\Sims.php:162
Stack trace:
> #0 E:\xampp\htdocs\inventory-web\common\models\Sims.php(162): yii\base\ErrorHandler->handleError(2, 'Creating defaul...', 'E:\\xampp\\htdocs...', 162, Array)
#1 E:\xampp\htdocs\inventory-web\backend\controllers\SimissueancetransactionController.php(400): common\models\Sims::change_status('', 'Production Stor...')
> #2 [internal function]: backend\controllers\SimissueancetransactionController->actionImport()
> #3 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#4 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\Controller.php(156): yii\base\InlineAction->runWithParams(Array)
> #5 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\Module.php(523): yii\base\Controller->runAction('import', Array)
#6 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module->runAction('simissueancetra...', Array)
> #7 E:\xampp\htdocs\inventory-web\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))
#8 E:\xampp\htdocs\inventory-web\backend\web\index.php(17): yii\base\Application->run()
> #9 {main}

162行是

  public static function change_status($id,$status){
    $sims = Sims::find()->where(['id'=>$id])->one();
    $sims->status = $status; // 162
    return $sims->save();
}

导入功能是

  public function actionImport(){
    $file_name = $_POST['file_name'];
    $header_index = $_POST['header_index'];
    $fieldSet = $_POST['field'];


    $data = \moonland\phpexcel\Excel::widget([
        'mode' => 'import',
        'fileName' => 'uploads/' . $file_name,
        'setFirstRecordAsKeys' => false, // if you want to set the keys of record column with first record, if it not set, the header with use the alphabet column on excel.
        'setIndexSheetByName' => false, // set this if your excel data with multiple worksheet, the index of array will be set with the sheet name. If this not set, the index will use numeric.
        'getOnlySheet' => 0, // you can set this property if you want to get the specified sheet from the excel data with multiple worksheet.
    ]);

    //loop therogh first sheet
    $ok_count = 0;
    $status_arr = [];
    $final_data = isset($data[0]) ? $data[0] : $data;
    foreach($final_data as $key=>$value)
    {
        if($key <= $header_index) continue;
        $sims = new SimIssueanceTransaction();

        foreach($value as $k=>$v){


            $v = preg_replace('/\s+/', ' ', trim($v));
            if(isset($fieldSet[0]['imsi']) && $fieldSet[0]['imsi']==$k){
                $sims->sim_id = Sims::imsiToidexcel($v);
                $sims->imsi =$v."";

            }

            if(isset($fieldSet[0]['issued_to']) && $fieldSet[0]['issued_to']==$k){
                $sims->issued_to = $v;
            }

            if (isset($fieldSet[0]['purpose']) && $fieldSet[0]['purpose'] == $k) {
                $sims->purpose = $v;
            }

        }
        $sims->issued_at = date('Y-m-d H:i:s');
        $sims->issued_by = Yii::$app->user->id;


        if($sims->purpose=='Local SIM Issue')
        {
            Sims::change_status($sims->sim_id,Sims::$status_titles[1]);
        }
        else
        {
            Sims::change_status($sims->sim_id,Sims::$status_titles[2]);
        }

        Sims::sim_user($sims->sim_id,$sims->issued_to);
        if($sims->save())
        {
            $ok_count++;
        }
        else
        {
            $status_arr[] = $sims->errors;
        }


    }

    return $this->render('excel_finish', ['records_saved' => $ok_count,'status_arr'=>$status_arr]);
}

我找不到主要问题,因为已经说change_status函数有效,但为什么它会给我错误?任何帮助都将受到高度赞赏。

0 个答案:

没有答案