/** * @return string * @throws ServerErrorHttpException * @throws \yii\base\InvalidConfigException * @throws \yii\web\BadRequestHttpException */ public function run() { $params = Yii::$app->request->getBodyParams(); $form = new ImageUploadForm(['basePath' => $this->basePath, 'baseUrl' => $this->baseUrl]); $form->setAttributes($params); if (!$form->validate()) { HttpError::the400(); } if (!$form->save() && !$form->hasErrors()) { HttpError::the500('Failed to upload file for unknown reason.'); } $response = Yii::$app->getResponse(); $response->setStatusCode(201); $response->getHeaders()->set('Location', $form->getLink()); return $form; }
/** * Get primary key of current handling model * @param bool $throwException * @return string * @throws \yii\web\BadRequestHttpException */ public function getModelPk($throwException = true) { if ($this->_modelPk !== false && is_callable($this->_modelPk)) { $this->_modelPk = call_user_func($this->_modelPk, $this); } if ($this->_modelPk === false) { $this->_modelPk = Yii::$app->request->get($this->pkName); } if ($this->_modelPk == null && $throwException) { HttpError::the400(); } return $this->_modelPk; }