示例#1
0
 public function actionCreate()
 {
     $pad = new Pad();
     if ($pad->load(Yii::$app->request->post()) && $pad->validate()) {
         Yii::$app->user->identity->link('pads', $pad);
         Yii::$app->session->setFlash('success', 'Pad is successfully created.');
         return $this->redirect('note/list');
     }
     return $this->render('create', ['pad' => $pad]);
 }
示例#2
0
 /**
  * Get pad or raise 404
  *
  * @param integer $id pad id
  * @return Pad
  * @throws \yii\web\HttpException
  */
 private function getPad($id)
 {
     $pad = Pad::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->getId()]);
     if (!$pad) {
         throw new \yii\web\HttpException(404, 'Not Found');
     }
     return $pad;
 }
示例#3
0
 public function delete($id, Request $request, Pad $padModel)
 {
     $pad = $this->padExists($id);
     if (!$pad) {
         return $response->redirect('/pads');
     }
     $pad->delete();
     $request->session->add(['success' => 'Pad deleted successfuly.']);
     return app('twig')->render('pads/index.htm', ['pads' => $padModel->all()]);
 }
示例#4
0
 public function update($id, Request $request, Note $noteModel, Pad $padModel)
 {
     $note = $this->noteExists($id);
     if (!$note) {
         return $response->redirect('/notes');
     }
     $pads = $padModel->where('user_id', $request->user()->id)->get();
     $rules = ['name' => 'required', 'text' => 'required', 'pad' => 'required|exists:pads,id'];
     $validator = app('validation')->make($request->all(), $rules);
     if ($validator->fails()) {
         $request->session->add(['errors' => $validator->errors()->all()]);
         return app('twig')->render('notes/edit.htm', ['note' => $note, 'pads' => $pads]);
     }
     $note->name = $request->input('name');
     $note->text = $request->input('text');
     $note->pad_id = $request->input('pad');
     $note->save();
     $request->session->add(['success' => 'Note updated successfuly.']);
     return app('twig')->render('notes/edit.htm', ['note' => $note, 'pads' => $pads]);
 }
示例#5
0
文件: Note.php 项目: Kabie/notejam
 /**
  * Get pad
  *
  * @return app\models\Pad
  */
 public function getPad()
 {
     return $this->hasOne(Pad::className(), ['id' => 'pad_id']);
 }
示例#6
0
文件: User.php 项目: shutkos/notejam
 /**
  * Get pads
  */
 public function getPads()
 {
     return $this->hasMany(Pad::className(), ['user_id' => 'id']);
 }