/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $id * @return string|\yii\web\Response * @throws ForbiddenHttpException */ public function actionCreate($id) { $note = Note::findOne($id); if ($note->creator == Yii::$app->user->id) { $model = new Access(); $model->load(Yii::$app->request->post()); $model->note_id = $id; if ($model->validate() && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } throw new ForbiddenHttpException("Not allowed share notes other people!"); }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @param $id * @return string|\yii\web\Response * @throws BadRequestHttpException * @throws ForbiddenHttpException */ public function actionCreate($id) { $note = Note::findOne($id); if (!$note) { throw new BadRequestHttpException("Not exists note!"); } if ($note->creator == Yii::$app->user->id) { $model = new Access(); $usersForAutocomplete = User::find()->selectForAutocomplite()->notCurrent()->asArray()->all(); $model->load(Yii::$app->request->post()); $model->note_id = $id; if ($model->validate() && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'usersForAutocomplete' => $usersForAutocomplete]); } } throw new ForbiddenHttpException("Not allowed share notes other people!"); }