public function actionCreate() { $this->breadcrumbs = array($this->ID . ' Manager' => array('index'), 'Create' => array('create')); $model = new Roles(); if (isset($_POST['Roles'])) { $model->attributes = $_POST['Roles']; if ($model->validate()) { $model->save(); Yii::app()->db->createCommand('insert into authitem(name, type, description) values(:name, 2, :description)')->execute(array(':name' => $model->alias, ':description' => $model->title)); $this->redirect(array('roles/index')); } } $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 User(); $profile = new Profile(); $roles = new Roles(); $this->performAjaxValidation(array($model, $profile)); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password); $profile->attributes = $_POST['Profile']; $roles->attributes = $_POST['Roles']; $profile->user_id = 0; if ($model->validate() && $profile->validate() && $roles->validate()) { $model->password = Yii::app()->controller->module->encrypting($model->password); if ($model->save()) { $profile->user_id = $model->id; $profile->save(); $roles->save(); } $this->redirect(array('view', 'id' => $model->id)); } else { $profile->validate(); } } $this->render('_form', array('model' => $model, 'profile' => $profile, 'roles' => $roles)); }
function createRole($aData) { $con = Propel::getConnection(RolesPeer::DATABASE_NAME); try { $con->begin(); $sRolCode = $aData['ROL_CODE']; $sRolSystem = $aData['ROL_SYSTEM']; $status = $fields['ROL_STATUS'] = 1 ? 'ACTIVE' : 'INACTIVE'; $oCriteria = new Criteria('rbac'); $oCriteria->add(RolesPeer::ROL_CODE, $sRolCode); $oCriteria->add(RolesPeer::ROL_SYSTEM, $sRolSystem); $oDataset = RolesPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $aRow = $oDataset->getRow(); if (is_array($aRow)) { return $aRow; } if (!isset($aData['ROL_NAME'])) { $aData['ROL_NAME'] = ''; } $rol_name = $aData['ROL_NAME']; unset($aData['ROL_NAME']); $obj = new Roles(); $obj->fromArray($aData, BasePeer::TYPE_FIELDNAME); if ($obj->validate()) { $result = $obj->save(); $con->commit(); $obj->setRolName($rol_name); G::auditLog("CreateRole", "Role Name: " . $rol_name . " - Role Code: " . $aData['ROL_CODE'] . " - Role Status: " . $status); } else { $e = new Exception("Failed Validation in class " . get_class($this) . "."); $e->aValidationFailures = $this->getValidationFailures(); throw $e; } return $result; } catch (exception $e) { $con->rollback(); throw $e; } }