public function newCategory() { $validate = new Validate(); $validated = $validate->Validate_Category(); $nameToSlug = $this->nameToSlug($validated); if (\Auth::check()) { if ($validated->passes() && $nameToSlug === true) { $slug = \Input::get('name'); $slug = preg_replace('#[ -]+#', '-', $slug); $slug = strtolower($slug); \DB::beginTransaction(); try { $item = new \MenuCategory(); $item->menu_category_name = \Input::get('name'); $item->menu_category_slug = $slug; $item->save(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); return \Redirect::to('admin/category/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved!</p></div>'); } if ($nameToSlug === false) { return \View::make('categories.new')->withErrors($validated)->withInput(array('name'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">That category already exists!'); } return \View::make('categories.new')->withErrors($validated)->withInput(array('name')); } return \Redirect::to('admin'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new MenuCategory(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['MenuCategory'])) { $model->attributes = $_POST['MenuCategory']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
<?php include 'admin-config.php'; $menucategory_id = $menucategory_name = $menucategory_status = $error = ""; if (strlen(Request::post("submit"))) { $menucategory_id = Request::post("menucategory_id"); $menucategory_name = Request::post("menucategory_name"); $menucategory_status = Validation::getStautsTinyVal(Request::post("active")); $menucategoryObj = new MenuCategory(); $menucategoryObj->set("menucategory_id", $menucategory_id); $menucategoryObj->set("menucategory_name", $menucategory_name); $menucategoryObj->set("menucategory_status", $menucategory_status); if ($menucategoryObj->save()) { General::redirectUrl("menu_category.php"); } else { $error = "Menu Category Name alreday exist !"; } } include 'header.php'; include 'sitebar.php'; ?> <div class="ch-container"> <div class="row"> <div id="content" class="col-lg-10 col-sm-10"> <!-- content starts --> <div> <ul class="breadcrumb"> <li> <a href="menu_category.php">Home</a> </li>