Пример #1
0
 /**
  * Creates a new Friend model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Friend();
     $model->user_id = Yii::$app->user->getId();
     if ($model->load(Yii::$app->request->post())) {
         // get user_id of email
         $user_id = $model->lookupEmail($model->email);
         if ($user_id === false) {
             $user_id = $model->addUser($model->email);
         }
         $model->friend_id = $user_id;
         // validate the form against model rules
         if ($model->validate()) {
             // all inputs are valid
             $model->save();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             // validation failed
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }