/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Goal(); // Associate goal with current user. $model->userId = Yii::app()->user->id; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Goal'])) { $model->attributes = $_POST['Goal']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created Project in the database. * * @return Response */ public function store() { $project = new Project(); $input = Input::all(); $project->title = $input['title']; $project->contact_firstname = $input['contact_firstname']; $project->contact_lastname = $input['contact_lastname']; $project->contact_email = $input['contact_email']; $project->contact_phone_number = $input['contact_phone_number']; $project->contact_phone_number_ext = $input['contact_phone_number_ext']; $project->description = $input['description']; $project->location = $input['location']; $project->expected_time = $input['expected_time']; $project->motivation = $input['motivation']; $project->resources = $input['resources']; $project->constraints = $input['constraints']; $project->state = 1; //Application state $project->user_id = Auth::user()->id; if ($project->save()) { foreach ($input['goals'] as $goal) { if ($goal == '') { continue; } else { $goalObj = new Goal(); $goalObj->project_id = $project->id; $goalObj->goal = $goal; $goalObj->complete = 0; $goalObj->save(); } } foreach ($input['tags'] as $tag) { if ($tag == '') { continue; } else { $tagObj = Tag::find($tag); $project->tags()->attach($tagObj); } } return Redirect::to('/project/create')->with('info', 'The project application has been submitted.'); } else { return Redirect::to('/project/create')->withErrors($project->errors()); } }