Example #1
0
 /**
  * Метод - удаление новости по id
  * @param int $id
  */
 public function deleteNews(int $id)
 {
     $news = News::findById($id);
     if (false !== $news) {
         $news->delete();
     }
 }
Example #2
0
<?php

require __DIR__ . '/autoload.php';
$view = new \View\php\View();
$view->title = 'Мой крутой сайт';
//для примера с урока
$view->news = \Model\News::findAll();
//Получение массива новостей
$view->display(__DIR__ . '/View/templates/index.php');
Example #3
0
 public function __construct()
 {
     $this->model = \Model\News::instance();
 }
Example #4
0
<?php

require __DIR__ . '/../autoload.php';
$view = new \View\php\View();
$view->article = \Model\News::findById($_GET['id']);
//сохраняем в свойство article опеределенную новость по id
$view->display(__DIR__ . '/../View/templates/article.php');
//подключаем шаблон
Example #5
0
 /**
  * Try to store a posted post, and redirect on successes or errors.
  *
  * @return RedirectResponse
  */
 public function store()
 {
     $request = RequestWrapper::$request;
     try {
         $this->hasCreateRole($this->pc);
         $account = $this->pc ? Account::findByChar($this->pc) : null;
         $account_id = $account->id();
     } catch (InvalidArgumentException $e) {
         $error = "Sorry, you must be logged in to try to save a news post.";
         return new RedirectResponse('/news/?error=' . rawurlencode($error));
     } catch (ErrorException $e) {
         $error = "Sorry, you don't have permission to save a news post.";
         return new RedirectResponse('/news/?error=' . rawurlencode($error));
     }
     // Handle POST
     $news_title = $request->get('news_title');
     $news_content = $request->get('news_content');
     $tag = $request->get('tag');
     // Create new post
     if (!empty($news_content)) {
         try {
             // News Model
             $news = new News();
             $news->createPost($news_title, $news_content, $account_id, $tag);
             return new RedirectResponse('/news/?create_successful=1');
         } catch (InvalidArgumentException $e) {
             return new RedirectResponse('/news/?error=' . rawurlencode('Unable to create news post.'));
         }
     } else {
         return new RedirectResponse('/news/create/?error=' . rawurlencode('A News post must have a body.'));
     }
 }