Exemplo n.º 1
0
 /**
  * Creates a new Tag model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Tag();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['code' => '200', 'message' => 'Create Tag success'];
             } else {
                 return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new Tag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tag();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
Exemplo n.º 3
0
 /**
  * Creates a new Tag model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tag();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 4
0
 /**
  * Creates a new Meta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tag();
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Exemplo n.º 5
0
 public function actionAdd()
 {
     $model = new Tag();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '成功添加标签“' . $model->name . '”。');
             return $this->redirect(['index']);
         } else {
             Yii::$app->session->setFlash('danger', '标签添加失败。');
         }
     }
     return $this->render('form', ['model' => $model]);
 }