示例#1
0
 /**
  * Add tag modal window
  * @return array
  */
 public function actionAddNewTag()
 {
     if (Yii::$app->request->isAjax) {
         $model = new NewsTag();
         if (Yii::$app->request->isPost) {
             foreach (Yii::$app->request->post('NewsTagTranslation', []) as $language => $data) {
                 foreach ($data as $attribute => $translation) {
                     $model->translate($language)->{$attribute} = $translation;
                 }
             }
         }
         if (Yii::$app->request->isPost) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             if ($model->save()) {
                 return ['newId' => $model->id, 'newName' => $model->name];
             } else {
                 return ['errors' => FieldHelper::showErrors($model)];
             }
         } else {
             return $this->renderAjax('newTagAjax', ['model' => $model]);
         }
     } else {
         throw new BadRequestHttpException();
     }
 }