index.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. define('APP_PATH', realpath('..'));
  3. try {
  4. // Load the config
  5. $config = include APP_PATH . "/app/config/config.php";
  6. // Register an autoloader
  7. $loader = new \Phalcon\Loader();
  8. $loader->registerDirs(array(
  9. $config->application->controllersDir,
  10. $config->application->modelsDir
  11. ))->register();
  12. // Create a DI
  13. $di = new Phalcon\DI\FactoryDefault();
  14. // Setting up the router
  15. $di->set('router', require APP_PATH . '/app/config/routes.php');
  16. //MetaData
  17. $di->set('modelsMetadata', function(){
  18. if (function_exists('apc_store')) {
  19. return new Phalcon\Mvc\Model\MetaData\Apc();
  20. } else {
  21. return new Phalcon\Mvc\Model\MetaData\Files(array(
  22. 'metaDataDir' => APP_PATH . "/app/compiled-templates/"
  23. ));
  24. }
  25. });
  26. // Setting up the view component (seems to be required even when not used)
  27. $di->set('view', function() use ($config) {
  28. $view = new \Phalcon\Mvc\View();
  29. $view->setViewsDir($config->application->viewsDir);
  30. $view->registerEngines(array(
  31. ".volt" => function($view, $di) {
  32. $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
  33. $volt->setOptions(array(
  34. "compiledPath" => APP_PATH . "/app/compiled-templates/",
  35. "compiledExtension" => ".compiled",
  36. "compiledSeparator" => '_',
  37. ));
  38. return $volt;
  39. }
  40. ));
  41. return $view;
  42. });
  43. // Setting up the database connection
  44. $di->set('db', function() use ($config) {
  45. $database = $config->database;
  46. return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
  47. 'host' => $database->host,
  48. 'username' => $database->username,
  49. 'password' => $database->password,
  50. 'dbname' => $database->name,
  51. 'options' => array(
  52. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  53. )
  54. ));
  55. });
  56. // Handle the request
  57. $application = new \Phalcon\Mvc\Application();
  58. $application->setDI($di);
  59. echo $application->handle()->getContent();
  60. } catch(\Phalcon\Exception $e) {
  61. echo "PhalconException: ", $e->getMessage();
  62. }