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 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]);
 }
Example #3
0
<?php

define("PHP_EXT", '.php');
define('PROJ_PATH', '/home/artem/server/nginx/www/book/');
define('VIEWS_PATH', PROJ_PATH . 'app/views/');
define('CORE_PATH', PROJ_PATH . 'app/core/');
require_once PROJ_PATH . 'app/config.php';
require_once CORE_PATH . 'exceptions.php';
require_once CORE_PATH . 'base/Model.php';
require_once CORE_PATH . 'base/View.php';
require_once CORE_PATH . 'base/Controller.php';
require_once CORE_PATH . 'base/Router.php';
require_once CORE_PATH . 'db/DatabaseRecord.php';
try {
    $db = new PDO("mysql:" . "dbname=" . $config['db']['name'] . ";host=" . $config['db']['host'], $config['db']['user'], $config['db']['pass']);
    $db->exec("SET NAMES SET" . $config['character']);
    DatabaseRecord::setDatabase($db);
} catch (PDOException $e) {
    echo "PDO error: " . $e->getMessage() . "\n";
}
$router = new Router();
try {
    $router->startRouting();
} catch (NotFoundException $e) {
    Controller::redirectTo404($_SERVER['REQUEST_URI']);
}
Example #4
0
<?php

define("PHP_EXT", '.php');
define('APP_PATH', __DIR__ . '/');
define('VIEWS_PATH', APP_PATH . 'views/');
define('CORE_PATH', APP_PATH . 'core/');
define('TOOLS_PATH', CORE_PATH . 'tools/');
require_once APP_PATH . 'config.php';
require_once CORE_PATH . 'exceptions.php';
require_once CORE_PATH . 'systemFunctions.php';
require_once CORE_PATH . 'base/Model.php';
require_once CORE_PATH . 'base/View.php';
require_once CORE_PATH . 'base/Controller.php';
require_once CORE_PATH . 'base/App.php';
require_once CORE_PATH . 'db/DatabaseRecord.php';
try {
    $db = new PDO("mysql:" . "dbname=" . $config['db']['name'] . ';' . "host=" . $config['db']['host'], $config['db']['user'], $config['db']['pass']);
    DatabaseRecord::setDatabase($db, $config['character']);
} catch (PDOException $e) {
    echo "PDO error: " . $e->getMessage() . "\n";
}
$app = new App($config);
try {
    $app->run();
} catch (NotFoundException $e) {
    Controller::redirectTo404(explode('?', $_SERVER['REQUEST_URI'])[0]);
}