Example #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Project();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Project'])) {
         $model->attributes = $_POST['Project'];
         if ($model->save()) {
             // Set project creator as owner.
             $user = User::model()->findByPk($model->create_user_id);
             $model->associateUserToProject($user);
             $model->associateUserToRole('owner', $user->id);
             $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()
 {
     if (!Yii::app()->user->checkAccess('createProject')) {
         throw new CHttpException(403, 'You are not authorized to perform this action.');
     }
     $model = new Project();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Project'])) {
         $model->attributes = $_POST['Project'];
         if ($model->save()) {
             $model->associateUserToRole('owner', Yii::app()->user->id);
             $model->associateUserToProject(Yii::app()->user);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }