/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Major(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Major'])) { $model->attributes = $_POST['Major']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->major_id)); } } $this->render('create', array('model' => $model)); }
public function postMajor($academy_id) { $userInput = ['name' => Input::get('major_name'), 'academy_id' => $academy_id]; $rules = ['name' => 'required']; $validator = Validator::make($userInput, $rules); if ($validator->passes()) { $major = new Major(); $major->name = $userInput['name']; $major->academy_id = $userInput['academy_id']; $major->save(); return Redirect::to("/admin/academy/{$academy_id}"); } else { return Redirect::to("/admin/academy/{$academy_id}")->withErrors($validator); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAjaxCreate() { $model = new Major(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Major'])) { $model->attributes = $_POST['Major']; if ($model->save()) { $this->redirect(array('index')); } } $this->renderPartial('_form', array('model' => $model)); }
/** * Add a major to DB if it does not already exist. */ public static function add($name) { $name = trim($name); if ($name == '') { return NQ::simple('intern', INTERN_WARNING, 'No name given for new major. No major was added.'); } /* Search DB for major with matching name. */ $db = self::getDb(); $db->addWhere('name', $name); if ($db->select('count') > 0) { NQ::simple('intern', INTERN_WARNING, "The major <i>{$name}</i> already exists."); return; } /* Major does not exist...keep going */ $major = new Major(); $major->name = $name; $major->hidden = 0; try { $major->save(); } catch (Exception $e) { NQ::simple('intern', INTERN_ERROR, "Error adding major <i>{$name}</i>.<br/>" . $e->getMessage()); return; } /* Major was successfully added. */ NQ::simple('intern', INTERN_SUCCESS, "<i>{$name}</i> added as undergraduate major."); }