index.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. use App\Controllers\HomeController;
  3. use App\Controller;
  4. //use App\Models\HomeModel;
  5. $error_reporting = 1; // 1 = errors 0 = none
  6. if ($error_reporting == 1){
  7. ini_set('display_errors', 1);
  8. ini_set('display_startup_errors', 1);
  9. error_reporting(E_ALL);}
  10. session_start();
  11. $_SESSION["messages"] = null;
  12. if (array_key_exists("messages", $_COOKIE)) {
  13. }
  14. else{
  15. $_COOKIE["messages"] = null;
  16. }
  17. require(__DIR__ . "/../vendor/autoload.php");
  18. global $config;
  19. $config = parse_ini_file(__DIR__ . "/../config/config.php");
  20. $loader = new Twig_Loader_Filesystem(__DIR__ . "/../views/");
  21. $twig = new Twig_Environment($loader);
  22. $twig->addGlobal('config', $config);
  23. require(__DIR__ . "/../app/View.php");
  24. $router = new AltoRouter();
  25. $router->setBasePath('');
  26. $router->map('GET','/', "App\Controllers\HomeController#index", 'home');
  27. $router->map('GET|POST','/upload', "App\Controllers\HomeController#upload", 'upload');
  28. $router->map('GET|POST','/print', "App\Controllers\HomeController#print", 'print');
  29. $match = $router->match();
  30. // not sure if code after this comment is the best way to handle matched routes
  31. list( $controller, $action ) = explode( '#', $match['target'] );
  32. if ( is_callable(array($controller, $action)) ) {
  33. $obj = new $controller($twig);
  34. call_user_func_array(array($obj,$action), array($match['params']));
  35. } else if ($match['target']==''){
  36. echo 'Error: no route was matched';
  37. //possibly throw a 404 error
  38. } else {
  39. echo 'Error: can not call '.$controller.'#'.$action;
  40. //possibly throw a 404 error
  41. }