/** * Creates a new UserAddress model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new UserAddress(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->user_id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionProfile($id) { $model = $this->findModel($id); if ($model === null) { throw new NotFoundHttpException('The requested page does not exist.'); } else { if (Yii::$app->user->id === $model->id) { $profileModel = UserProfile::findOne(['user_id' => Yii::$app->user->id]); if (is_null($profileModel)) { $profileModel = new UserProfile(); } $workModel = new UserWorkExperience(); $query = new Query(); $query->from(UserWorkExperience::tableName()); $query->where(['user_id' => $id]); $userWorkDataProvider = new ActiveDataProvider(['query' => $query]); $educationModel = new UserEducation(); $query = new Query(); $query->from(UserEducation::tableName()); $query->where(['user_id' => $id]); $educationDataProvider = new ActiveDataProvider(['query' => $query]); $addressModel = new UserAddress(); $query = new Query(); $query->from(UserAddress::tableName()); $query->where(['user_id' => $id]); $addressDataProvider = new ActiveDataProvider(['query' => $query]); if ($profileModel->load(Yii::$app->request->post()) && $profileModel->beforeSave(true) && $profileModel->save()) { } if ($workModel->load(Yii::$app->request->post()) && ($workModel->user_id = $model->id) && $workModel->beforeSave(true) && $workModel->save()) { $workModel = new UserWorkExperience(); } if ($educationModel->load(Yii::$app->request->post()) && ($educationModel->user_id = $model->id) && $educationModel->beforeSave(true) && $educationModel->save()) { $educationModel = new UserEducation(); } if ($addressModel->load(Yii::$app->request->post()) && ($addressModel->user_id = $model->id) && $addressModel->beforeSave(true) && $addressModel->save()) { $addressModel = new UserAddress(); } return $this->render('profile', ['model' => $model, 'profileModel' => $profileModel, 'workModel' => $workModel, 'workDataProvider' => $userWorkDataProvider, 'educationModel' => $educationModel, 'educationDataProvider' => $educationDataProvider, 'addressModel' => $addressModel, 'addressDataProvider' => $addressDataProvider]); } else { throw new NotFoundHttpException('Access Denied. You need to be owner to perform this operation.'); } } }