public function actionHoletypes() { $model = new HoleTypes(); // uncomment the following code to enable ajax-based validation /* if(isset($_POST['ajax']) && $_POST['ajax']==='hole-types-holetypes-form') { echo CActiveForm::validate($model); Yii::app()->end(); } */ $err = ""; if (isset($_POST['HoleTypes'])) { $model->attributes = $_POST['HoleTypes']; switch ($_POST['subBtn']) { case "Add": if ($model->validate()) { try { $model->save(); $err = "Created"; } catch (Exception $e) { $err = "some error " . $e->getMessage(); } } break; case "Edit": if ($model->validate()) { try { $rec = $model->find('id=:id and lang=:lang', array(':id' => $model->id, ':lang' => $model->lang)); $rec->attributes = $model->attributes; $rec->update(); $err = "Updated"; } catch (Exception $e) { $err = "some error " . $e->getMessage(); } } break; case "Delete": try { $rec = $model->find('id=:id and lang=:lang', array(':id' => $model->id, ':lang' => $model->lang)); $rec->delete(); $err = "Deleted"; } catch (Exception $e) { $err = "some error " . $e->getMessage(); } break; } } $this->render('holetypes', array('model' => $model, 'err' => $err)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new HoleTypes(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['HoleTypes'])) { $model->attributes = $_POST['HoleTypes']; $model->ordering = $model->LastOrder + 1; if ($model->save()) { $this->redirect(array('index')); } } $this->render('create', array('model' => $model)); }