/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserXata(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['UserXata'])) { $model->attributes = $_POST['UserXata']; 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 Xata(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Xata'])) { $data = $_POST['Xata']; //$data['Xata']['owner']=1;//Yii::app()->user->id; if ($cntry_id = Country::check($data['country_caption'], $data['country_short'])) { if ($city_id = City::check($data['city_caption'], $cntry_id)) { unset($data['country_short']); unset($data['country_caption']); unset($data['city_caption']); $type_id = 0; for ($i = 2; $i >= 0; $i--) { if (isset($_POST['type_id_lvl' . $i])) { if ($type_id = (int) $_POST['type_id_lvl' . $i]) { break; } } } if ($type_id) { $data['type_id'] = $type_id; } $data['owner'] = Yii::app()->user->id; // Saving owner as current user $data['city_id'] = $city_id; $model->attributes = $data; if ($model->save()) { $userXata = new UserXata(); $userXata->attributes = array('uid' => Yii::app()->user->id, 'xid' => $model->getPrimaryKey(), 'rights' => hexdec('FFFFFF'), 'public' => 10); if ($userXata->save()) { $this->redirect(array('view', 'id' => $model->id)); } } } // if city is setted } // if country is setted } // if there is POST $this->render('create', array('model' => $model)); }