Пример #1
0
$debugbar = new StandardDebugBar();
$debugbar->addCollector(new DebugBar\Bridge\SlimCollector($app));
$loader = new Twig_Loader_Filesystem('.');
$env = new DebugBar\Bridge\Twig\TraceableTwigEnvironment(new Twig_Environment($loader));
$debugbar->addCollector(new DebugBar\Bridge\Twig\TwigCollector($env));
$debugbarRenderer = $debugbar->getJavascriptRenderer();
$view->appendData(['debugbarRenderer' => $debugbarRenderer]);
/* -- */
$view->parserOptions['debug'] = true;
$view->parserExtensions = array(new \Slim\Views\TwigExtension(), new \Twig_Extension_Debug());
/*$app->get('/', function() use($app) {
	$app->render('index.twig');
});*/
$app->get('/', function () use($app) {
    $em = new \App\EntityManager('news');
    $news = $em->findAll();
    $app->render('index.twig', compact('news'));
})->name('home');
/** Inject variable into twig **/
$folders = App\App::getFolders();
$view->appendData(['navigation' => $folders]);
$router = new App\ConfigManager();
$view->appendData(['router' => $router]);
/**  ---- **/
require "routes.php";
/** Inject variable into twig **/
$site = App\App::getConfig('site');
$view->appendData(['site' => $site]);
/**  ---- **/
//$app->get('/emix/:article', 'App\AppController:test')->name('news.show');
$app->run();
Пример #2
0
 static function init()
 {
     if (!defined('HIANO_APP_PATH')) {
         die('ERROR:HIANO_APP_PATH undefined!');
     }
     spl_autoload_register(array('Hiano\\ClassLoader', 'load'));
     if (App\App::getConfig()->get('debug.enable', false)) {
         $debug_config = App\App::getConfig()->get('debug');
         error_reporting($debug_config['error_reporting']);
         unset($debug_config);
     } else {
         error_reporting(0);
     }
     if (App\App::getConfig()->get('timezone')) {
         date_default_timezone_set(App\App::getConfig()->get('timezone'));
     }
     if ($session_path = App\App::getConfig()->get('session_path')) {
         //todo load and register SessionDriver
         //$session_driver = Hiano::loadDriver('\\Hiano\\')
         //\Hiano\Session\SessionManager::register();
     }
     //\Hiano\App\App::registerModelPath(HIANO_APP_PATH . '/widgets/models');
     $app_path = realpath(HIANO_APP_PATH);
     \Hiano\App\App::registerModelPath($app_path . '/Model');
     \Hiano\App\App::registerImportPath($app_path . '/Include');
     App\App::setErrorHandler(function ($ex) {
         /* @var $ex \Hiano\ErrorException */
         throw new \Exception("Error[{$ex->getCode()}]:" . $ex->getMessage());
     });
     App\App::setRedirectHandler(function ($ex) {
         /* @var $ex \Hiano\RedirectException */
         header('Location:' . $ex->getRedirectUrl());
     });
 }