/** * Creates new category * @return string|Response */ public function actionCreate() { $category = new Category(); if ($category->load(Yii::$app->request->post())) { $this->performModelSave($category, ['success' => function () { return ['message' => Yii::t('management', 'Category has been added')]; }, 'fallback' => function ($category) { return $this->redirect(['update', 'id' => $category->id]); }]); } return $this->render('create', ['category' => $category]); }
/** * Updates an existing Post model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $post = $this->findModel(['id' => $id]); $categories = Category::find()->orderBy('title')->all(); if ($post->load(Yii::$app->request->post()) && $post->save()) { return $this->redirect(['update', 'id' => $post->id]); } else { return $this->render('update', ['post' => $post, 'categories' => $categories]); } }