示例#1
0
function loadTwigi18n()
{
    $loader = new Twig_Loader_Filesystem('../public');
    $twig = new Twig_Environment($loader, array());
    //$twig->clearCacheFiles();
    \Slim\Extras\Views\Twig::$twigOptions = array('debug' => true);
    $twig->addExtension(new Twig_Extensions_Extension_I18n());
    \Slim\Extras\Views\Twig::$twigExtensions = array('Twig_Extension_Debug', 'Twig_Extensions_Extension_I18n');
}
require VENDOR_PATH . 'Paris/idiorm.php';
require VENDOR_PATH . 'Paris/paris.php';
// Models
require 'models/Article.php';
require 'models/Author.php';
// Configuration
# ORM::configure('sqlite:' . ROOT_PATH . '/sql/database.db');
ORM::configure('mysql:host=localhost;dbname=blog');
ORM::configure('username', 'root');
ORM::configure('password', '');
#ORM::logging(true);
// Slim Configuration
\Slim\Slim::registerAutoloader();
// Twig Configuration
\Slim\Extras\Views\Twig::$twigDirectory = VENDOR_PATH . 'Twig';
\Slim\Extras\Views\Twig::$twigOptions = array("debug" => true);
if (is_writable(ROOT_PATH . 'cache')) {
    \Slim\Extras\Views\Twig::$twigOptions['cache'] = ROOT_PATH . 'cache';
}
// Twig i18n config
\Slim\Extras\Views\Twig::$twigExtensions = array('Twig_Extensions_Extension_I18n');
$locality = $site_cfg['website']['i18n'];
// locality should be determined here
require_once APP_PATH . 'config/locales.php';
// Setup $app
$app = new \Slim\Slim(array('templates.path' => APP_PATH . 'views/' . $site_cfg['website']['theme'] . '/', 'locales.path' => APP_PATH . 'i18n/', 'debug' => true, 'view' => new \Slim\Extras\Views\Twig(), 'log.enabled' => false, 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(array('path' => ROOT_PATH . 'logs', 'name_format' => 'Y-m-d', 'message_format' => '%label% - %date% - %message%'))));
// Cookie
$app->add(new \Slim\Middleware\SessionCookie(array('expires' => '40 minutes', 'path' => '/', 'domain' => 'slim', 'secure' => false, 'httponly' => false, 'encrypt' => false, 'name' => 'slimblog', 'secret' => md5($site_cfg['website']['secret']))));
// Authenticate
$app->add(new \SlimBasicAuth('', 'admin'));
$app->add(new \CsrfGuard());
示例#3
0
<?php

require 'vendor/autoload.php';
require 'lib/idiorm.php';
require 'config.php';
$pdf_enable = file_exists($WKHTMLTOPDF_BIN_PATH) ? TRUE : FALSE;
define('PROJECT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('WKHTMLTOPDF_BIN_PATH', $WKHTMLTOPDF_BIN_PATH);
define('PDF_ENABLE', $pdf_enable);
ORM::configure("mysql:dbname={$DB_NAME};host={$DB_HOST}");
ORM::configure('username', $DB_USER);
ORM::configure('password', $DB_PASS);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ORM::configure('id_column_overrides', array('customer' => 'customer_id', 'quotation' => 'quotation_id', 'option' => 'option_id'));
$app = new \Slim\Slim(array('mode' => 'production', 'debug' => false, 'log.enable' => true, 'templates.path' => 'tpl'));
\Slim\Extras\Views\Twig::$twigOptions = array('charset' => 'utf-8', 'cache' => realpath('./tpl_cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view(new \Slim\Extras\Views\Twig());
require 'app.php';
$app->run();
示例#4
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\Slim(array('templates.path' => __DIR__ . '/../templates'));
\Slim\Extras\Views\Twig::$twigOptions = array('charset' => 'utf-8', 'cache' => realpath('../templates/cache'));
$app->view(new \Slim\Extras\Views\Twig());
$app->get('/', function () use($app) {
    $app->render('index.html.twig');
});
$app->run();
示例#5
0
        if (in_array(\PTA\App::$Cat_Engage_Code, $ProductTypes) == true) {
            if (preg_match('/^\\/home/', $request_path) != 0 || preg_match('/^\\/support/', $request_path) != 0 || preg_match('/^\\/amember/', $request_path) != 0) {
                return true;
            } else {
                $app->redirect('/amember4/member');
            }
        }
        $app->redirect('/amember4/signup');
    }
});
$app->hook('slim.after.router', function () use($app) {
    # Disable caching for all content types other than images
    $response = $app->response();
    if (substr($response['Content-Type'], 0, 6) === 'image/') {
        $response['Cache-Control'] = 'public, max-age=86400';
        $response['Expires'] = gmdate('D, d M Y H:i:s GMT', strtotime('+1 day'));
    } else {
        $response['Pragma'] = 'nocache';
        $response['Cache-Control'] = 'no-cache, no-store, max-age=0, must-revalidate';
        $response['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT';
    }
});
# Set options for the Twig template engine
\Slim\Extras\Views\Twig::$twigOptions = ['auto_reload' => true, 'autoescape' => true, 'charset' => 'utf-8', 'strict_variables' => false];
$twig = $app->view()->getEnvironment();
$twig->addGlobal('remote_ip', $_SERVER['REMOTE_ADDR']);
# Import routes from separate include files
require 'lib/routes.inc.php';
require 'lib/routes-api.inc.php';
# Execute Slim to handle the request
$app->run();
示例#6
0
<?php

$config = ['slim' => ['templates.path' => SS_APP_PATH . '/templates', 'log.level' => \Slim\Log::DEBUG, 'log.enabled' => TRUE, 'log.writer' => new \Slim\Extras\Log\DateTimeFileWriter(['path' => SS_APP_PATH . '/logs', 'name_format' => 'Y-m-d.\\l\\o\\g'])], 'twig' => ['charset' => 'utf-8', 'cache' => SS_APP_PATH . '/cache/templates', 'auto_reload' => TRUE, 'strict_variables' => FALSE, 'autoescape' => TRUE]];
$app = new \Slim\Slim($config['slim']);
\Slim\Extras\Views\Twig::$twigOptions = $config['twig'];
$app->view(new \Slim\Extras\Views\Twig());