/** * This method accepts an array of data and creates the model. * Returns true if successfully created. * Returns the error validated model if validation fails. * * data array should have the following hash keys - * 1. id (optional) * 2. label * 3. value * * @param array $data * @return string|model */ public static function createSetting($data) { $model = new GlobalSettings(); $model->attributes = $data; if ($model->save()) { return true; } else { return $model; } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new GlobalSettings(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['GlobalSettings'])) { $model->attributes = $_POST['GlobalSettings']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }