예제 #1
0
 public function actionInsertlog()
 {
     $model = new Logdata();
     $model->scenario = 'create';
     $datas = Yii::$app->request->post();
     $logFile = $datas['logFile'];
     $logDatas = $datas['data'];
     $remoteIp = $_SERVER['REMOTE_ADDR'];
     $objects = json_decode($logDatas, true);
     try {
         foreach ($objects as $object) {
             $model->isNewRecord = true;
             $model->setAttributes(['data' => $object, 'logFile' => $logFile, 'remoteIp' => $remoteIp]);
             if (!$model->save()) {
                 throw new Exception("保存失败");
             } else {
                 $model->id = 0;
             }
         }
         $res = ['statusCode' => 200, 'message' => '保存成功'];
     } catch (Exception $e) {
         Yii::error("出错了啦:" . $e->getMessage());
         $res = ['statusCode' => 300, 'message' => $e->getMessage()];
     }
     return Json::encode($objects);
 }
예제 #2
0
 public function actionAdd()
 {
     $model = new Logdata();
     $model->scenario = 'create';
     $model->attributes = Yii::$app->request->post();
     if ($model->save()) {
         $data = ['statusCode' => 200, 'tabid' => 'core-user', 'closeCurrent' => true, 'message' => '保存成功'];
     } else {
         $message = array_values($model->firstErrors);
         $data = ['statusCode' => 300, 'message' => implode('<br>', $message)];
     }
     return Json::encode($data);
 }