/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { //create is name of scenario $model = new User('scenarioCreate'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->encryptPassword(); $transaction = Yii::app()->db->beginTransaction(); try { if ($model->save()) { $successful = true; if ($model->assignRolesToUser($model->id) == $successful) { $transaction->commit(); /*if (!empty($_POST['yt1'])) { Yii::app()->user->setFlash('activityGuarantee-created', "¡La actividad <b><i>"$model->description"</i></b> fue creada exitosamente!"); $model=new ActivityGuarantee; } else*/ $this->redirect(array('view', 'id' => $model->id)); } else { $transaction->rollBack(); } } } catch (Exception $e) { $transaction->rollBack(); } } if (Role::model()->count('active = 1') > 0) { $this->render('create', array('model' => $model)); } else { if (Role::model()->count('active = 0') > 0) { throw new CHttpException('', 'Primero debes ' . CHtml::link('crear rol', array('role/create')) . ' o ' . CHtml::link('activar ', array('role/admin')) . 'algún rol' . '.'); } else { throw new CHttpException('', 'Primero debes ' . CHtml::link('crear rol', array('role/create')) . '.'); } } }