/**
  * Creates a new UserPlace model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new UserPlace();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #2
0
 public function add($user_id, $place_id)
 {
     // check if it exists
     if (!UserPlace::find()->where(['user_id' => $user_id, 'place_id' => $place_id])->exists()) {
         // if not, add it
         $up = new UserPlace();
         $up->user_id = $user_id;
         $up->place_id = $place_id;
         $up->save();
     }
 }