示例#1
0
文件: Api.php 项目: collegefb/web
 public function getApp(Container $container)
 {
     $app = new \SlimController\Slim(array('controller.class_prefix' => 'CollegeFBWeb\\Controllers\\Api', 'controller.method_suffix' => 'Action', 'di' => $container));
     $app->addRoutes(array('/' => 'Index:index', '/colleges(/)' => 'Colleges:index', '/colleges/:id_college' => 'College:index', '/conferences(/)' => 'Conferences:index', '/conferences/:id_conference' => 'Conference:index', '/news(/)' => 'News:index', '/news/:id_news' => 'SingleNews:index'));
     $app->add(new \SlimJson\Middleware(array('json.status' => false, 'json.override_error' => true, 'json.override_notfound' => true, 'json.cors' => true)));
     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;
 }
示例#3
0
<?php

/* load app */
require 'app/bootstrap.php';
// register Slim auto-loader
\Slim\Slim::registerAutoloader();
// init app
$app = new \SlimController\Slim(array('templates.path' => ABSPATH . '/FindSite/View', 'Controller.class_prefix' => '\\FindSite\\Controller', 'Controller.class_suffix' => 'Controller', 'Controller.method_suffix' => 'Action', 'Controller.template_suffix' => 'php'));
// add content type middleware, so the JSON request will be parsed automatically
$app->add(new \Slim\Middleware\ContentTypes());
// add session middleware
$app->add(new \Slim\Middleware\SessionCookie(array('expires' => '60 minutes', 'path' => '/', 'domain' => null, 'secure' => false, 'httponly' => false, 'name' => 'slim_session', 'secret' => 'flS3p4PCRD', 'cipher' => MCRYPT_RIJNDAEL_256, 'cipher_mode' => MCRYPT_MODE_CBC)));
$app->addRoutes(array('/' => 'Home:index', '/agent' => 'Agent:index', '/agent/contact' => 'Agent:contact', '/site' => 'Site:index', '/site/list' => 'Site:list', '/site/add' => 'Site:add', '/site/detail/:id' => 'Site:detail', '/user' => 'User:index', '/user/login' => 'User:login', '/user/register' => 'User:register'));
/* init error handler*/
$errorHandler = new \FindSite\Infrastructure\Handler\ErrorHandler($app);
$errorHandler->register();
$app->run();
<?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();
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);
    ORM::configure('logger', function ($log_string, $query_time) use($app) {
        $app->getLog()->debug('Query [' . $log_string . '] time: [' . $query_time . ' seconds]');
    });
} else {
    $app->config('debug', false);
}
// load routes
require_once APP_PATH . '/app/routes.php';
// run the app
$app->run();