/** * Finds the LogUpload model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LogUpload the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = LogUpload::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $keys = \yii\helpers\Json::decode($mod->keys); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Setting(); $not = Util::excelNot(); foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Setting(); } else { $model = Setting::findOne($value['id']); } foreach ($keys as $v) { $model->{$v} = $value[$v]; } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $params = \yii\helpers\Json::decode($mod->params); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Setting(); $not = Util::excelNot(); foreach ($modelAttribute->attributeLabels() as $k => $v) { if (!in_array($k, $not)) { $attr[] = $k; } } foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Setting(); } else { $model = Setting::findOne($value['id']); } foreach ($attr as $at) { if (isset($value[$at])) { if ($value[$at]) { $model->{$at} = trim($value[$at]); } } } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }