public function actionShow() { $url = end(App::parseRoute($_SERVER['REQUEST_URI'])['routes']); $article = Article::findOne(['url_crc' => crc32($url)]); _debug('Url: ' . $url . ' (crc: ' . crc32($url) . ')'); if (empty($article)) { return Controller::redirectTo404($_SERVER['REQUEST_URI']); } $comments = $article->getComments(); return $this->view->render('showArticle', ['article' => $article, 'commentsCount' => count($comments), 'comments' => $comments]); }
public function actionShowArticle() { if (!$_GET['id']) { return Controller::redirectTo404($_SERVER['REQUEST_URI']); } if (!($article = Article::findOne($_GET['id']))) { return Controller::redirectTo404($_SERVER['REQUEST_URI']); } $comments = $article->getComments(); return $this->view->render('showArticle', ['article' => $article, 'commentsCount' => count($comments), 'comments' => $comments]); }
public function actionModifyArticle() { $article; if (isset($_GET['id'])) { $article = Article::findOne($_GET['id']); } else { $article = new Article(); //fix $article->title = ''; $article->content = ''; $article->img_preview_url = ''; $article->author_id = 1; $article->save(); } $this->view->render('modifyArticle', ['article' => $article], 'admin'); }