Пример #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrganizationAddresses()
 {
     return $this->hasMany(OrganizationAddress::className(), ['org_id' => 'id']);
 }
 public function actionProfile($id)
 {
     $model = $this->findModel($id);
     if (Yii::$app->user->id === $model->user_id) {
         $model = $this->findModel($id);
         $workModel = OrganizationWork::find()->where(['org_id' => $id])->one();
         if ($workModel === null) {
             $workModel = new OrganizationWork();
         }
         $addressModel = new OrganizationAddress();
         $query = new Query();
         $query->from(OrganizationAddress::tableName());
         $query->where(['org_id' => $id]);
         $addressDataProvider = new ActiveDataProvider(['query' => $query]);
         if ($model->load(Yii::$app->request->post()) && $model->beforeSave() && $model->save()) {
         }
         if ($workModel->load(Yii::$app->request->post()) && $workModel->beforeSave(true) && $workModel->save()) {
         }
         if ($addressModel->load(Yii::$app->request->post()) && ($addressModel->org_id = $model->id) && $addressModel->beforeSave(true) && $addressModel->save()) {
             $addressModel = new OrganizationAddress();
         }
         return $this->render('profile', ['model' => $model, 'workModel' => $workModel, 'addressModel' => $addressModel, 'addressDataProvider' => $addressDataProvider]);
     } else {
         throw new NotFoundHttpException('Access Denied. You need to be owner to perform this operation.');
     }
 }