/** * Creates a new PostMeta model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new PostMeta(); $model->order = 999; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Add new meta data for current media. * * @param $meta_name * @param $meta_value * * @return bool */ public function setMeta($meta_name, $meta_value) { if (is_array($meta_value) || is_object($meta_value)) { $meta_value = Json::encode($meta_value); } $model = new PostMeta(); $model->media_id = $this->id; $model->meta_name = $meta_name; $model->meta_value = $meta_value; return $model->save(); }
/** * Add new meta data for current post. * * @param $meta_name * @param $meta_value * * @return bool */ public function setMeta($meta_name, $meta_value) { if (is_array($meta_value) || is_object($meta_value)) { $meta_value = Json::encode($meta_value); } if ($this->getMeta($meta_name) !== null) { return $this->upMeta($meta_name, $meta_value); } else { $model = new PostMeta(); $model->post_id = $this->id; $model->meta_name = $meta_name; $model->meta_value = $meta_value; return $model->save(); } }
/** * Add new meta data for current post. * * @param string $name * @param string|array $value * @return bool */ public function setMeta($name, $value) { if (is_array($value) || is_object($value)) { $value = Json::encode($value); } if ($this->getMeta($name) !== null) { return $this->upMeta($name, $value); } $model = new PostMeta(['post_id' => $this->id, 'name' => $name, 'value' => $value]); return $model->save(); }