index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. try {
  3. // Load the config
  4. $config = include(__DIR__."/../app/config/config.php");
  5. // Register an autoloader
  6. $loader = new \Phalcon\Loader();
  7. $loader->registerDirs(array(
  8. $config->application->controllersDir,
  9. $config->application->modelsDir
  10. ))->register();
  11. // Create a DI
  12. $di = new Phalcon\DI\FactoryDefault();
  13. // Setting up the router
  14. $di->set('router', function() use ($config) {
  15. return include($config->application->routes);
  16. });
  17. // Setting up the view component (seems to be required even when not used)
  18. $di->set('view', function() use ($config) {
  19. $view = new \Phalcon\Mvc\View();
  20. $view->setViewsDir($config->application->viewsDir);
  21. return $view;
  22. });
  23. // Setting up the database connection
  24. $di->set('db', function() use ($config) {
  25. return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
  26. "host" => $config->database->host,
  27. "username" => $config->database->username,
  28. "password" => $config->database->password,
  29. "dbname" => $config->database->name
  30. ));
  31. });
  32. // Handle the request
  33. $application = new \Phalcon\Mvc\Application();
  34. $application->setDI($di);
  35. echo $application->handle()->getContent();
  36. } catch(\Phalcon\Exception $e) {
  37. echo "PhalconException: ", $e->getMessage();
  38. }