示例#1
0
文件: Web.php 项目: collegefb/web
 public function getApp(Container $container)
 {
     $app = new \SlimController\Slim(array('controller.class_prefix' => 'CollegeFBWeb\\Controllers\\Web', 'controller.method_suffix' => 'Action', 'templates.path' => $container['web_templates_path'], 'controller.template_suffix' => 'twig', 'di' => $container));
     $app->addRoutes(array('/' => 'Index:home', '/conferences(/:division)' => 'Conferences:list', '/conference/:conference' => 'Conferences:one', '/colleges(/:division)' => 'Colleges:list', '/college/:college' => 'Colleges:one'));
     $app->view(new \Slim\Views\Twig());
     $app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
     return $app;
 }
示例#2
0
文件: Admin.php 项目: collegefb/web
 public function getApp(Container $container)
 {
     $app = new \SlimController\Slim(array('controller.class_prefix' => 'CollegeFBWeb\\Controllers\\Admin', 'controller.method_suffix' => 'Action', 'templates.path' => $container['admin_templates_path'], 'controller.template_suffix' => 'twig', 'di' => $container));
     $app->addRoutes(array('/dashboard' => 'Index:dashboard', '/logout' => 'Index:logout', '/login' => 'Index:login'));
     $app->view(new \Slim\Views\Twig());
     $app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
     $app->add(new \CollegeFBWeb\Slim\Middleware\Auth('Index:login', 'Index:logout', 'Index:dashboard'));
     return $app;
 }
<?php

// Errors
error_reporting(E_ALL);
ini_set('display_errors', '1');
date_default_timezone_set('UTC');
// Load
require '../vendor/autoload.php';
// Load configs
$config = (require '../app/Config/config.php');
$routes = (require '../app/Config/routes.php');
// Session
session_cache_limiter(false);
session_start();
// Startup
$app = new \SlimController\Slim(['mode' => $config['app_mode'], 'debug' => $config['app_debug'], 'cookies.lifetime' => $config['app_cookie_ttl'], 'cookies.secret_key' => $config['app_cookie_secret'], 'view' => new \Slim\Views\Twig(), 'templates.path' => '../app/Templates', 'controller.class_prefix' => '\\Controllers', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php', 'cookies.encrypt' => true]);
// Views
$view = $app->view();
$view->parserOptions = ['debug' => $config['app_debug'], 'cache' => '../cache'];
$view->parserExtensions = [new \Slim\Views\TwigExtension()];
$view->setTemplatesDirectory('../app/Templates/');
// Add global values
$app->config = $config;
$app->view->getEnvironment()->addGlobal('config', $config);
// Add moltin middleware
$app->add(new \Middleware\Moltin($config));
// Routes
$app->addRoutes($routes);
// GO!
$app->run();
<?php

// define a working directory
define('APP_PATH', __DIR__);
// PHP v5.3+
require APP_PATH . '/../vendor/autoload.php';
date_default_timezone_set('UTC');
session_start();
// Prepare app
$app = new \SlimController\Slim(array('templates.path' => APP_PATH . '/../templates', 'controller.class_prefix' => '\\dealdb\\Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'twig'));
// Prepare view
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath(APP_PATH . '/../templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->view->parserExtensions = array(new \Slim\Views\TwigExtension());
// Define routes
$app->addRoutes(array('/' => 'Stat:index', '/clearQiwi' => 'Stat:clearQiwi', '/add' => ['get' => 'Deal:add', 'post' => 'Deal:addDeal'], '/all' => 'Deal:all', '/export' => 'Deal:export'));
// Run app
$app->run();
$dotenv = new \Dotenv\Dotenv(APP_PATH);
$dotenv->load();
$dotenv->required(['APP_DEBUG']);
// define the app
$app = new \SlimController\Slim();
// configure application
$app->config(['templates.path' => APP_PATH . '/app/views', 'controller.class_prefix' => '\\app\\controllers', 'controller.class_suffix' => 'Controller', 'controller.method_suffix' => 'Action', 'view' => new \Slim\Views\Twig(), 'log.enabled' => true, 'log.level' => \Slim\Log::DEBUG, 'log.writer' => new \Slim\Logger\DateTimeFileWriter(['path' => APP_PATH . '/storage/logs'])]);
// configure models
require_once APP_PATH . '/vendor/j4mie/idiorm/idiorm.php';
require_once APP_PATH . '/vendor/j4mie/paris/paris.php';
ORM::configure('mysql:host=' . getenv('DB_HOST') . ';dbname=' . getenv('DB_NAME'));
ORM::configure('username', getenv('DB_USERNAME'));
ORM::configure('password', getenv('DB_PASSWORD'));
Model::$auto_prefix_models = '\\app\\models\\';
// configure views
$app->view()->parserOptions = ['debug' => true, 'cache' => APP_PATH . '/storage/twig'];
$app->view()->parserExtensions = [new \Slim\Views\TwigExtension(), new \src\twig\TwigExtension()];
// environment depending settings
if (getenv('APP_DEBUG') == 'true') {
    // configure logging
    $app->config('debug', true);
    // configure request logging
    $app->hook('slim.after.router', function () use($app) {
        $request = $app->request;
        $response = $app->response;
        $app->log->debug(sprintf('Request path: %s - Response status: %d', $request->getPathInfo(), $response->getStatus()));
    });
    // configure error reporting
    $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
    // configure model logging
    ORM::configure('logging', true);
示例#6
0
<?php

session_start();
require 'vendor/autoload.php';
$app = new \SlimController\Slim(array('templates.path' => 'templates'));
$app->view(new \Slim\Views\Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$app->hook('slim.before', function () use($app) {
    $app->view()->appendData(array('baseUrl' => '/tester/ebay_trading_api'));
});
$app->container->singleton('db', function () {
    $server = 'localhost';
    $user = '******';
    $pass = '';
    $database = 'ebaytrading';
    return new mysqli($server, $user, $pass, $database);
});
$app->container->singleton('ebay', function () use($app) {
    $id = 1;
    $settings_result = $app->db->query("SELECT user_token, run_name, dev_id, app_id, cert_id, site_id FROM settings WHERE id = {$id}");
    $settings = $settings_result->fetch_object();
    return new Ebay($settings);
});
$app->addRoutes(array('/' => 'Home:index', '/settings' => 'Settings:view', '/settings/update' => 'Settings:update', '/products/new' => 'Product:new', '/products/create' => 'Product:create', '/upload' => 'Product:upload', '/session' => 'Home:session', '/token' => 'Home:token', '/categories' => 'Product:categories'));
$app->run();