Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2.  
  3. use Phalcon\Loader;
  4. use Phalcon\Mvc\View;
  5. use Phalcon\Mvc\Url as UrlProvider;
  6. use Phalcon\Mvc\Application;
  7. use Phalcon\DI\FactoryDefault;
  8. use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
  9. use Phalcon\Config\Adapter\Ini as ConfigIni;
  10. use Phalcon\Session\Adapter\Files as Session;
  11.  
  12. try
  13. {
  14.     $config = new ConfigIni("../backend/configs/config.ini");
  15.  
  16.     $loader = new Loader();
  17.     $loader->registerDirs(array(
  18.         $config->app->controllers,
  19.         $config->app->models,
  20.         $config->app->library
  21.     ))->register();
  22.  
  23.     $di = new FactoryDefault();
  24.  
  25.     // Setup the database service
  26.     $di->set('db', function() use ($config){
  27.         return new DbAdapter(array(
  28.             "host"     => $config->database->host,
  29.             "username" => $config->database->username,
  30.             "password" => $config->database->password,
  31.             "dbname"   => $config->database->database
  32.         ));
  33.     });
  34.  
  35.     $di->set('session', function()
  36.     {
  37.         $session = new Session();
  38.         $session->start();
  39.         return $session;
  40.     });
  41.  
  42.     $di->set("view", function() use ($config)
  43.     {
  44.         $view = new View();
  45.         $view->setViewsDir($config->app->views);
  46.  
  47.         $view->registerEngines(array(
  48.             '.volt' => 'Phalcon\Mvc\View\Engine\Volt',
  49.             '.phtml' => 'Phalcon\Mvc\View\Engine\Volt'
  50.         ));
  51.  
  52.         return $view;
  53.     });
  54.  
  55.     // Setup a base URI so that all generated URIs include the "tutorial" folder
  56.     $di->set('url', function() use ($config){
  57.         $url = new UrlProvider();
  58.         $url->setBaseUri($config->app->basedir);
  59.         return $url;
  60.     });
  61.  
  62.     $di->set('elements', function() use($config){
  63.         $element =  new Elements();
  64.         $element->SetSiteName( $config->web->sitename );
  65.         return $element;
  66.     });
  67.  
  68.  
  69.     // Handle the request
  70.     $application = new Application($di);
  71.     $application->setDI($di);
  72.  
  73.     echo $application->handle()->getContent();
  74. }
  75. catch(\Exception $e)
  76. {
  77.     echo "Bootstrap error -> " . $e->getMessage();
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement