/**
  * Creates a new CountryOrgRel model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($oid)
 {
     $org = Organization::findOne(['id' => $oid]);
     $countries = Country::find()->all();
     $rels = CountryOrgRel::find()->where(['org_id' => $oid])->all();
     $model = new CountryOrgRel();
     if (Yii::$app->request->post()) {
         $model->load(Yii::$app->request->post());
         $count = CountryOrgRel::find()->where(['org_id' => $model->org_id, 'country_id' => $model->country_id])->count();
         if ($count == 0) {
             $model->save();
         }
         return $this->redirect(['create', 'oid' => $model->org_id]);
     } else {
         return $this->render('create', ['model' => $model, 'org' => $org, 'countries' => $countries, 'rels' => $rels]);
     }
 }
 /**
  * Finds the Organization model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Organization the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Organization::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }