public function postCreate() { $validator = Validator::make(Input::all(), Warranty::$rules); if ($validator->passes()) { $warranty = new Warranty(); $warranty->user_id = Auth::user()->id; $warranty->title = Input::get('title'); $warranty->extra = Input::get('extra'); $warranty->save(); return Redirect::to('warranty/index')->with('message', 'Warranty Request Sent'); } return Redirect::to('warranty/index')->with('message', 'Something went wrong')->withErrors($validator)->withInput(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Warranty(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Warranty'])) { $model->attributes = $_POST['Warranty']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Warranty(); if (isset($_GET['id'])) { $model->dev_id = $_GET['id']; } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Warranty'])) { $model->attributes = $_POST['Warranty']; $model->status = 1; $model->dt_start = UserFunctions::toFull($model->dt_start); $model->dt_end = UserFunctions::toFull($model->dt_end); if (Warranty::getCompanyID($model->dev_id) == User::getMyCompany() || Yii::app()->user->role == 1) { if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } else { throw new CHttpException(403, 'У вас нет прав в этой организации'); } } $this->render('create', array('model' => $model)); }