/** * Creates a new Note model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Note(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Note::find()->where(['user_id' => \Yii::$app->user->id])->orderBy('id DESC')]); $model = new Note(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->refresh(); } return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); }
public function actionCreate() { $note = new Note(); # to make value in dropdown selected, strange yii2 behavior $note->pad_id = Yii::$app->request->get('pad'); if ($note->load(Yii::$app->request->post()) && $note->validate()) { Yii::$app->user->identity->link('notes', $note); Yii::$app->session->setFlash('success', 'Note is successfully created.'); return $this->redirect('note/list'); } return $this->render('create', ['note' => $note]); }
public function actionCreate($pad) { $note = new Note(); $note->pad_id = $pad; if ($note->load(Yii::$app->request->post()) && $note->validate()) { /** @var User $user */ $user = Yii::$app->user->identity; $user->link('notes', $note); Yii::$app->session->setFlash('success', 'Note is successfully created.'); return $this->redirect('note/list'); } return $this->render('create', ['note' => $note]); }
public function actionCreate() { $note = new Note(); $note->visibility = Note::VIS_PUBLIC_LISTED; if ($note->load(Yii::$app->request->post()) && $note->validate()) { if (Yii::$app->user->isGuest) { $note->save(false); } else { $note->link('user', Yii::$app->user->identity); } return $this->redirect(['view', 'id' => $note->id]); } return $this->render('create', ['note' => $note]); }
public function actionCreate() { $note = new Note(); if ($note->load(Yii::$app->request->post()) && $note->save()) { // get 5 latest notes $notes = Note::find()->where(['belong_to' => $this->data_post['belong_to'], 'type_area' => $this->data_post['type_area']])->orderBy('id DESC')->limit(5)->all(); // merge returned data $res_data = array_merge($this->data_post, ['notes' => $notes, 'disViewMore' => false]); return ['errors' => '', 'data' => $this->renderPartial('@widget/views/notes/_list', $res_data)]; } else { // get 5 latest notes $notes = Note::find()->where(['belong_to' => $this->data_post['belong_to'], 'type_area' => $this->data_post['type_area']])->orderBy('id DESC')->limit(5)->all(); // merge returned data $res_data = array_merge($this->data_post, ['notes' => $notes, 'disViewMore' => false]); return ['errors' => $note->getErrors(), 'data' => $this->renderPartial('@widget/views/notes/_list', $res_data)]; } }
/** * Creates a new Note model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Note(); $ajax = Yii::$app->request->isAjax; if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->session->setFlash('success', 'Data berhasil disimpan.'); $model = new Note(); } else { Yii::$app->session->setFlash('error', 'Data gagal disimpan.'); } if ($ajax) { return $this->renderAjax('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } } else { if ($ajax) { return $this->renderAjax('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } } }
public function actionAddNote() { Yii::$app->response->format = Response::FORMAT_JSON; if (Yii::$app->request->isGet) { $model = new Note(); $model->user_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->get()) && $model->save()) { Note::updateAll(['status' => 'update'], ['id' => $model->parent_id]); if ($model->parent_id == '') { return ['status' => 1, 'message' => 'done', 'new_id' => $model->id]; } else { return ['status' => 1, 'message' => 'done']; } } else { return ['status' => 0, 'message' => $model->errors]; } } return ['status' => 0, 'message' => 'request error']; }