예제 #1
0
파일: app.php 프로젝트: andybp85/booyaamps
<?php

error_reporting(E_ALL & ~E_NOTICE);
// Smarty setup
// -----------------------------------------------------------------------------
$baseTemplate = strpos($_SERVER["REQUEST_URI"], 'admin') !== false ? 'admin-base' : 'base';
// figure out which main template to use
define('IS_AJAX', (bool) (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'));
// Fetch DI Container
$container = $app->getContainer();
// Register Smarty View helper
$container['view'] = function ($c) {
    $view = new \Slim\Views\Smarty(dirname(__FILE__) . '/templates', ['cacheDir' => dirname(__FILE__) . '/templates/cache', 'compileDir' => dirname(__FILE__) . '/templates/compiled', 'pluginsDir' => [dirname(__FILE__) . '/vendor/smarty/smarty/libs/plugins']]);
    $view->parserExtensions = array(dirname(__FILE__) . '/vendor/slim/views/SmartyPlugins');
    $view->addSlimPlugins($c['router'], $c['request']->getUri());
    return $view;
};
$smarty = $container['view']->getSmarty();
$smarty->compile_id = (bool) IS_AJAX ? 'ajaxResponse' : $baseTemplate;
// Auth
// -----------------------------------------------------------------------------
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
use Slim\Middleware\HttpBasicAuthentication\PdoAuthenticator;
$pdo = new PDO('mysql:host=' . $_ENV["BOOYA_DB_HOST"] . ';dbname=' . $_ENV["BOOYA_DB"], $_ENV["BOOYA_DB_USER"], $_ENV["BOOYA_DB_PASSWD"]);
$app->add(new \Slim\Middleware\HttpBasicAuthentication(["path" => "/admin", "secure" => false, "authenticator" => new PdoAuthenticator(["pdo" => $pdo])]));
// Page Routes
// -----------------------------------------------------------------------------
$app->get('/', function ($request, $response, $args) use($smarty) {
    return $this->view->render($response, 'pages/home.tpl', ['ParentTemplate' => $smarty->compile_id . '.tpl', 'page' => 'home']);
})->setName('home');