Esempio n. 1
0
 public function actionSave($id = null)
 {
     $user = UserModel::isAuthorized();
     if (!$user) {
         $this->redirect("/user/auth");
     }
     $input = \System\Engine::getInput();
     $data = $input->getArray("data");
     $data = array_intersect_key($data, array_flip(['title', 'content']));
     $data['user_id'] = $user->id;
     if ($id) {
         $post = PostModel::get($id);
         Validate::check($post->user_id == $user->id, "У вас не прав для редактирования этого блога", 403);
     } else {
         $post = new PostModel();
     }
     $post->setData($data);
     $post->save();
     $this->redirect("/");
 }