/** * Creates a new CategoryModel model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CategoryModel(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function add() { if (Request::check(['name'], "POST")) { $category = new CategoryModel(); $category->name = Request::get('name'); $category->save(); $this->set("success", "A categoria {$category->name} foi adicionada."); } return View('category.new'); }
public function actionCreate() { $errors = []; $name = ''; $sortOrder = ''; $status = ''; $categories = CategoryModel::getAll(false, true); $totalCategories = CategoryModel::getTotal(); $currentCategory = $totalCategories + 1; if (isset($_POST['submit'])) { $name = FL::clearStr($_POST['name']); $status = FL::clearInt($_POST['status']); $sortOrder = FL::clearInt($currentCategory); if (!FL::isValue($name)) { $errors[] = 'Название не может быть пустым'; } if (empty($errors)) { $category = new CategoryModel(); $category->name = $name; $category->sort_order = $sortOrder; $category->status = $status; $res = $category->save(); if (!$res) { $errors[] = 'Произошла ошибка при добавлении!'; } else { FL::redirectTo('/admin/category'); } } } $view = new View(); $view->categories = $categories; $view->currentCategory = $currentCategory; $view->errors = $errors; $view->display('admin_category/create.php'); return true; }