/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Unidades();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Unidades'])) {
         $model->attributes = $_POST['Unidades'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->unidad_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function postCreate()
 {
     // create the validation rules ------------------------
     if (Input::get('unidad')) {
         $rules = array('abreviatura' => 'required');
     } else {
         $rules = array('unidad' => 'required');
     }
     // do the validation ----------------------------------
     $validator = Validator::make(Input::all(), $rules);
     // check if the validator failed -----------------------
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         $Unidades = new Unidades();
         $Unidades->nombre = Input::get('unidad');
         $Unidades->abreviatura = Input::get('abreviatura');
         if ($Unidades->save()) {
             return Redirect::to('dashboard/unidades/index/')->with('msg', 'Unidad creada con éxito.')->with('class', 'success');
         } else {
             return Redirect::back()->withInput()->with('msg', '¡Algo salió mal! Los datos no fueron guardados.')->with('class', 'error');
         }
     }
 }