Esempio n. 1
0
 protected function actionOne()
 {
     $id = (int) $_GET['id'];
     $this->view->article = \App\Models\News::findById($id);
     $this->view->title .= $this->view->article->title;
     $this->view->display(__DIR__ . '/../Views/article.php');
 }
Esempio n. 2
0
 protected function actionOne()
 {
     $this->view->news = \App\Models\News::findById($_GET['id']);
     if (!$this->view->news) {
         throw new \App\Exceptions\Err404('Новость не найдена ');
     }
     $this->view->displayTwig('one.twig', ['item' => $this->view->news]);
 }
Esempio n. 3
0
 protected function actionSave()
 {
     $id = (int) $_REQUEST['id'];
     $article = \App\Models\News::findById($id);
     $article->title = $_REQUEST['title'];
     $article->intro_text = $_REQUEST['intro_text'];
     $article->full_text = $_REQUEST['full_text'];
     $article->save();
     $this->view->message = "Новость обновлена";
     $this->view->display(__DIR__ . '/../Views/admin_redirect.php');
 }
Esempio n. 4
0
 /**
  * Метод вывода одной новости по её id
  *
  */
 protected function actionOne()
 {
     $id = (int) $_GET['id'] ?: false;
     if (empty($id)) {
         $this->redirect('/');
     }
     if (!empty($article = NewsModel::findById($id))) {
         $this->view->render('/news/one.html', ['article' => $article, 'resource' => \PHP_Timer::resourceUsage()]);
     } else {
         $this->view->erroradmin = false;
         throw new Exception404('Страница с такой новостью не найдена');
     }
 }
Esempio n. 5
0
 /**
  * Метод вывода одной новости по её id
  *
  */
 protected function actionOne()
 {
     $id = (int) $_GET['id'] ?: false;
     if (empty($id)) {
         $this->redirect('/');
     }
     if (!empty($this->view->article = NewsModel::findById($id))) {
         $this->view->display(__DIR__ . '/../templates/news/one.html');
     } else {
         $this->view->erroradmin = false;
         throw new Exception404('Страница с такой новостью не найдена');
     }
 }
Esempio n. 6
0
 /**
  * Метод вывода одной новости по её id
  *
  */
 protected function actionOne()
 {
     $id = (int) $_GET['id'] ?: false;
     if (empty($id)) {
         header('Location: /');
         exit(0);
     }
     if (!empty($this->view->article = NewsModel::findById($id))) {
         $this->view->title = 'Урок 4 Новости. Статья';
         $this->view->display(__DIR__ . '/../templates/news/one.html');
     } else {
         $this->view->title = 'Урок 4. Статья не найдена';
         $this->view->erroradmin = false;
         $this->view->display(__DIR__ . '/../templates/errors/404notnews.php');
         exit(0);
     }
 }
Esempio n. 7
0
 protected function actionSave()
 {
     try {
         if (isset($_POST['id'])) {
             $news = \App\Models\News::findById($_POST['id']);
             if (!$news) {
                 throw new \App\Exceptions\Err404('Новость не найдена ');
             }
         } else {
             $news = new \App\Models\News();
         }
         $news->fill($_POST);
         $news->save();
         header('Location: /admin/index');
         exit;
     } catch (\Lib\MultiException $e) {
         $this->view->errors = $e;
         $logger = new \App\LogUseLib();
         $logger->getArrMess($e);
         $this->view->news = $news;
         $this->view->display(__DIR__ . '/../templates/admin/edit.php');
     }
 }
Esempio n. 8
0
 /**
  * Метод удаления статьи по её id
  *
  */
 protected function actionDelete()
 {
     $id = (int) $_GET['id'] ?: false;
     if (!empty($article = NewsModel::findById($id))) {
         $article->delete();
     } else {
         $this->view->erroradmin = true;
         throw new Exception404('Страница с такой новостью не найдена');
     }
     $this->redirect('/admin/');
 }
Esempio n. 9
0
<?php

require __DIR__ . '/autoload.php';
if (!empty($_POST['name'])) {
    if (!empty($_POST['id'])) {
        $article = \App\Models\News::findById((int) $_GET['id']);
    } else {
        $article = new \App\Models\News();
    }
    $article->name = htmlspecialchars($_POST['name']);
    $article->preview_content = htmlspecialchars($_POST['preview_content']);
    $article->detail_content = htmlspecialchars($_POST['detail_content']);
    $article->date_create = htmlspecialchars($_POST['date_create']);
    $article->save();
    if (!empty($_POST['save'])) {
        header('Location: /');
    }
}
if (!empty($_GET['id'])) {
    $article = \App\Models\News::findById((int) $_GET['id']);
    if (!empty($_GET['del'])) {
        $article->delete();
        header('Location: /');
    }
} else {
    $article = new \App\Models\News();
}
include __DIR__ . '/views/article_edit.tpl';
Esempio n. 10
0
<?php

use App\Models\News;
require __DIR__ . '/../../autoload.php';
$id = $_GET['id'] ?: false;
if (!empty($id)) {
    if (!empty($article = News::findById($id))) {
        include __DIR__ . '/../Views/update.php';
    } else {
        echo 'Запись с таким id отсутствует';
    }
} else {
    header('Location: /');
}
Esempio n. 11
0
<?php

require __DIR__ . '/autoload.php';
$id = (int) $_GET['id'];
$article = \App\Models\News::findById($id);
//var_dump($article);
include __DIR__ . '/App/templates/article.php';
Esempio n. 12
0
<?php

use App\Models\News;
use App\View;
const STATUS_ACTIVE = 1;
require __DIR__ . '/../../autoload.php';
$post = $_POST;
if (!empty($post)) {
    if (empty($post['id_news'])) {
        $article = new News();
    } else {
        $article = News::findById($post['id_news']);
    }
    $article->title = trim($post['title']);
    $article->description = trim($post['description']);
    $article->published = date("Y-m-d H:i:s");
    $article->status = STATUS_ACTIVE;
    $article->author_id = 1;
    $article->save();
    $view = new View();
    $view->title = 'Страница статьи';
    $view->article = $article;
    $view->display(__DIR__ . '/../templates/one.html');
} else {
    header('Location: /');
    exit(0);
}
Esempio n. 13
0
<?php

require __DIR__ . '/autoload.php';
$id = isset($_GET['id']) ? $_GET['id'] : 1;
$news = \App\Models\News::findById($id);
include __DIR__ . '/App/Views/OneNews.php';
Esempio n. 14
0
 protected function actionOne()
 {
     $id = (int) $_GET['id'];
     $this->view->article = \App\Models\News::findById($id);
     $this->view->display(__DIR__ . '/../templates/one.php');
 }
Esempio n. 15
0
 /**
  * Метод удаления статьи по её id
  *
  */
 protected function actionDelete()
 {
     $id = (int) $_GET['id'] ?: false;
     if (!empty($article = NewsModel::findById($id))) {
         $article->delete();
     } else {
         $this->view->title = 'Урок 4. Статья не найдена';
         $this->view->erroradmin = true;
         $this->view->display(__DIR__ . '/../templates/errors/404notnews.php');
         exit(0);
     }
     header('Location: /admin/');
     exit(0);
 }