public function save() { if (isset($this->reading) and $this->reading != '') { $savemodel = new Calibration(); $savemodel->measure = 'mm'; $savemodel->height = $this->reading; $savemodel->sensorid = $this->sensorid; $savemodel->datetime = $this->date; $savemodel->youremail = $this->youremail; $savemodel->yourname = $this->yourname; $result = $savemodel->save(); $this->id = $savemodel->sensorid; return $result; } else { $savemodel = new File(); $savemodel->sensorid = $this->sensorid; $savemodel->startdate = $this->date; $savemodel->enddate = $this->date; $savemodel->status = 'processed'; $this->file = UploadedFile::getInstance($this, 'file'); $savemodel->extension = end(explode(".", $this->file->name)); $result = $savemodel->save(); // save to get the ID $savemodel->filename = $savemodel->id . "_" . $this->file->name; $path = Yii::getAlias('@app') . Yii::$app->params['uploadPath'] . $savemodel->filename; if ($result) { $this->file->saveAs($path); } $result = $savemodel->save(); $this->id = $savemodel->sensorid; return $result; } }
/** * Creates a new Calibration model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Calibration(); try { if ($model->load($_POST) && $model->save()) { return $this->redirect(Url::previous()); } elseif (!\Yii::$app->request->isPost) { $model->load($_GET); } } catch (\Exception $e) { $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); $model->addError('_exception', $msg); } return $this->render('create', ['model' => $model]); }