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; }
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; }
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 /* 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();
<?php error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors', 1); // define a working directory define('APP_PATH', __DIR__); // PHP v5.3+ // load require APP_PATH . '/vendor/autoload.php'; // init app $app = new \SlimController\Slim(array('templates.path' => APP_PATH . '/templates', 'controller.class_prefix' => '\\MyApp\\Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php')); $app->addRoutes(array('/feed/:type' => 'Feed\\Feed:index')); $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();
<?php use League\CLImate\CLImate; // Generate the pathinfo by getting the first argument of the script array_shift($argv); // Discard the filename $pathinfo = array_shift($argv); if (empty($pathinfo)) { $pathinfo = '--help'; } // Create our app instance $app = new SlimController\Slim(['debug' => false, 'controller.class_prefix' => '', 'controller.class_suffix' => '', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => '']); // Set up the environment so that Slim can route $app->environment = Slim\Environment::mock(['PATH_INFO' => $pathinfo]); // Define the help command. If it doesn't have a name it won't include itself $app->get('--help', function () use($app) { $writer = new CLImate(); $writer->bold()->out('Available commands:'); foreach ($app->router()->getNamedRoutes() as $route) { $writer->green()->out(' ' . $route->getPattern()); } }); // CLI-compatible not found error handler $app->notFound(function () use($app) { $writer = new CLImate(); $command = $app->environment['PATH_INFO']; $writer->red()->bold()->out(sprintf('Error: Cannot route to command "%s"', $command)); $helpRoute = $app->router()->getMatchedRoutes('GET', '--help', true); $helpRoute[0]->dispatch(); $app->stop(); });
<?php define('APP_PATH', dirname(__DIR__)); require APP_PATH . '/vendor/autoload.php'; // load configuration $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()));
<?php session_start(); \Slim\Slim::registerAutoloader(); $app = new \SlimController\Slim(array('templates.path' => dirname(__DIR__) . '/views/', 'cookies.secret_key' => md5('appsecretkey'), 'controller.class_prefix' => '', 'controller.method_suffix' => '', 'controller.template_suffix' => 'twig', 'mode' => 'production', 'debug' => true)); if ($app->config('debug') === true) { ini_set('display_errors', 'On'); error_reporting(E_ALL); $app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware()); } /** Create monolog logger and store logger in container as singleton * (Singleton resources retrieve the same log resource definition each time) * $app->log->info("Log error"); * try catch hook * $app->applyHook('log.request.info', $e->getMessage()); * $app->log->error($e); */ $app->container->singleton('log', function () use($app) { $logpath = dirname(__DIR__) . '/logs/' . date('Y/m'); $logfile = $logpath . '/' . date('d') . '.log'; $old = umask(0); if (!is_dir($logpath)) { mkdir($logpath, 0777, true); } if (!is_writable($logpath)) { chmod($logfile, 0777); } if (!file_exists($logfile)) { file_put_contents($logfile, ''); } umask($old);
<?php require 'vendor/autoload.php'; define('APP_PATH', dirname(__DIR__)); session_cache_limiter(false); session_start(); $app = new \Slim\Slim(); use RedBeanPHP\R; R::setup('mysql:host=localhost;dbname=naughtyfire', 'root', 'nitoryolai'); $app = new \SlimController\Slim(array('controller.class_prefix' => '\\Naughtyfire\\Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php')); $app->addRoutes(array('/' => 'Home:index', '/holiday/create' => 'Home:createHoliday', '/settings' => 'Home:settings', '/settings/update' => 'Home:updateSettings', '/recepients' => 'Home:recepients', '/recepients/new' => 'Home:newRecepient', '/recepients/create' => 'Home:createRecepient', '/notify' => 'Notifier:notify')); $view = $app->view(); $view->setTemplatesDirectory('./templates'); $app->run();
<?php error_reporting(-1); ini_set('error_reporting', E_ALL); // define a working directory define('APP_PATH', getenv('APP_PATH')); // load require APP_PATH . '/vendor/autoload.php'; // init app $app = new \SlimController\Slim(['debug' => true, 'templates.path' => APP_PATH . '/src/Retail/View', 'controller.class_prefix' => '\\Retail\\Controller', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'php']); $app->addRoutes(['/' => 'Index:index', '/product/:id' => 'Product:get', '/edit' => 'Product:edit', '/edit/:id' => 'Product:edit', '/add' => 'Product:add', '/product/:name' => ['post' => ['Home:hello', function () { error_log("THIS ROUTE IS ONLY POST"); }]]]); // bootstrap routes $app->run();
<?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();
<?php //mostrar erros no navegador error_reporting(E_ALL); ini_set("display_errors", 1); require '../vendor/autoload.php'; // init app $app = new \SlimController\Slim(array('templates.path' => '../src/PHPAuth/Views', 'controller.class_prefix' => '\\PHPAuth\\Controllers', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => 'html')); // monolog logger $app->container->singleton('log', function () { $log = new \Monolog\Logger('php-auth'); $log->pushHandler(new \Monolog\Handler\StreamHandler('../logs/php-auth.log', \Monolog\Logger::DEBUG)); return $log; }); // config views $app->view(new \Slim\Views\Twig()); $app->view->parserOptions = array('charset' => 'utf-8', 'cache' => realpath('../src/PHPAuth/Views/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true); $app->view->parserExtensions = array(new \Slim\Views\TwigExtension()); $app->addRoutes(array('/' => 'HomeController:index', '/roles' => 'RolesController:index', '/roles/new' => 'RolesController:new', '/roles/create' => array('post' => array('RolesController:create', function () { error_log("Roles create /roles/create"); })), '/roles/:id' => 'RolesController:show', '/roles/:id/update' => array('put' => array('RolesController:update', function () { error_log("Roles update /roles/update"); })), '/roles/:id/edit' => 'RolesController:edit', '/groups' => 'GroupsController:index', '/groups/new' => 'GroupsController:new', '/groups/create' => array('post' => array('GroupsController:create', function () { error_log("Groups create /groups/create"); })), '/groups/:id' => 'GroupsController:show', '/groups/:id/update' => array('put' => array('GroupsController:update', function () { error_log("Groups update /groups/update"); })), '/groups/:id/edit' => 'GroupsController:edit', '/users' => 'UsersController:index', '/users/new' => 'UsersController:new', '/users/create' => array('post' => array('UsersController:create', function () { error_log("users create /users/create"); })), '/users/:id' => 'UsersController:show', '/users/:id/update' => array('put' => array('UsersController:update', function () { error_log("users update /users/update"); })), '/users/:id/edit' => 'UsersController:edit'));