/** * Creates a new Access model. * For ajax request will return json object * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $request = Yii::$app->request; $model = new Access(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Create new Access", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { return ['forceReload' => 'true', 'title' => "Create new Access", 'content' => '<span class="text-success">Create Access success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Create new Access", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }
/** * Creates a new Access model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Access(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * 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. * @return mixed */ public function actionCreate() { $model = new Access(); $model->user_owner = Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $all_mynotes = Calendar::getDates(Yii::$app->user->id); $all_users = User::find()->where('id !=' . Yii::$app->user->id)->asArray()->all(); // print_r($all_mynotes); // print_r($all_users); // exit(); if ($all_mynotes) { return $this->render('create', ['model' => $model, 'all_users' => $all_users, 'all_mynotes' => $all_mynotes]); } else { return $this->redirect('calendar/create'); } } }
/** * 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!"); }