public function actionDelimage() { $id = \Yii::$app->request->post('id'); $img_attr = \Yii::$app->request->post('og_image') != '' ? \Yii::$app->request->post('og_image') : 'og_image'; $success = false; $uploadPath = \Yii::getAlias(\Yii::$app->getModule('seo')->uploadPath); $seo_model = SeoAttributes::findOne($id); $img_path = FileHelper::normalizePath(\Yii::getAlias($uploadPath) . $seo_model->{$img_attr}); $seo_model->{$img_attr} = ''; if ($seo_model->save($img_attr)) { try { unlink($img_path); $success = true; } catch (\Exception $e) { throw new FileNotFoundException('File not found'); } } return Json::encode(['success' => $success]); }
/** * @return array|null|SeoAttributes * @throws InvalidConfigException */ public function getSeo() { $seo = false; $model = $this->owner; if (!isset($this->model_name) || $this->model_name == '') { throw new InvalidConfigException("The 'model_name' option is required. For example, 'Items'"); } $seo = SeoAttributes::find()->where(['model' => $this->modelFromNamespace($this->model_name), 'model_id' => $model->id])->one(); /*if(null == $seo) { $seo = ''; }*/ return $seo; }