public function actionEdit($id) { $model = Moderation::findOne((int) $id); if (!$model) { throw new Exception("Запись не найдена!"); } if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post(), $model->formName()) && $model->validate() && !Yii::$app->request->post('nosave', false)) { $post = new Post(); $post->attributes = $model->attributes; $post->visible = true; $tags = Yii::$app->request->post($model->formName(), ['tags' => []])['tags']; if ($post->save()) { if (!empty($tags)) { foreach ($tags as $tag) { $modelTag = Tag::add($tag); if ($modelTag) { $post->link('tags', $modelTag); } } } $model->delete(); // публикация в твиттере ContentGenerator::Twitter($post); return $this->redirect('moderate'); } } return $this->render('_edit', ['model' => $model]); }