Exemplo n.º 1
0
 public function viewAction()
 {
     $fc = FrontController::getInstance();
     $model = new FrontModel();
     $articleModel = new ArticleTableModel();
     $userModel = new UserTableModel();
     $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
     if (!$id) {
         header('Location: /admin/notFound');
         exit;
     }
     $articleModel->setId($id);
     $articleModel->setTable('article');
     $article = $articleModel->readRecordsById();
     $userModel->setId($article[0]['author']);
     $userModel->setTable('user');
     $model->setData(['article' => $article, 'author' => $userModel->readRecordsById('id', 'id, username')]);
     $output = $model->render('../views/blog/view.php', 'withoutSlider');
     $fc->setPage($output);
 }
Exemplo n.º 2
0
 public function deleteArticleAction()
 {
     header('Content-type: text/plain; charset=utf-8');
     header('Cache-Control: no-store, no-cache');
     header('Expires: ' . date('r'));
     if (filter_has_var(INPUT_POST, 'id')) {
         $id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
     }
     $model = new ArticleTableModel();
     $model->setId($id);
     $model->setTable('article');
     echo $model->deleteRecord();
 }
Exemplo n.º 3
0
 public function editArticleAction()
 {
     $fc = FrontController::getInstance();
     $model = new AdminModel('Редактирование статьи');
     $articleModel = new ArticleTableModel();
     $userModel = new UserTableModel();
     $id = filter_var($fc->getParams()['id'], FILTER_SANITIZE_NUMBER_INT);
     $articleModel->setId($id);
     $articleModel->setTable('article');
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $articleModel->setData();
         $articleModel->updateRecord();
         Session::setMsg('Статья успешно обновлена', 'success');
         header('Location: /admin/viewArticle/id/' . $articleModel->getArticle()->getData()['id']);
         exit;
     } else {
         $article = $articleModel->readRecordsById();
         $userModel->setId($article[0]['author']);
         $userModel->setTable('user');
         $model->setData(['article' => $article, 'author' => $userModel->readRecordsById('id', 'id, username')]);
         $output = $model->render('../views/admin/blog/editArticle.php', 'admin');
         $fc->setPage($output);
     }
 }