示例#1
0
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate() {
		$model=new UserChild;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['UserChild'])) {
			$model->attributes=$_POST['UserChild'];
			$this->updateChangelog($model);
			$model->password = md5($model->password);

			$profile=new ProfileChild;
			$profile->fullName=$model->firstName." ".$model->lastName;
			$profile->username=$model->username;
                        $profile->allowPost=1;
			$profile->emailAddress=$model->emailAddress;
			$profile->status=$model->status;

			if($model->save() && $profile->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 User();
     $groups = array();
     foreach (Groups::model()->findAll() as $group) {
         $groups[$group->id] = $group->name;
     }
     $roles = array();
     foreach (Roles::model()->findAll() as $role) {
         $roles[$role->id] = $role->name;
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         //$this->updateChangelog($model);
         $model->password = md5($model->password);
         $profile = new ProfileChild();
         $profile->fullName = $model->firstName . " " . $model->lastName;
         $profile->username = $model->username;
         $profile->allowPost = 1;
         $profile->emailAddress = $model->emailAddress;
         $profile->status = $model->status;
         if ($model->save() && $profile->save()) {
             if (isset($_POST['roles'])) {
                 $roles = $_POST['roles'];
                 foreach ($roles as $role) {
                     $link = new RoleToUser();
                     $link->roleId = $role;
                     $link->userId = $model->id;
                     $link->save();
                 }
             }
             if (isset($_POST['groups'])) {
                 $groups = $_POST['groups'];
                 foreach ($groups as $group) {
                     $link = new GroupToUser();
                     $link->groupId = $group;
                     $link->userId = $model->id;
                     $link->username = $model->username;
                     $link->save();
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'groups' => $groups, 'roles' => $roles, 'selectedGroups' => array(), 'selectedRoles' => array()));
 }