Guest User

Untitled

a guest
Jul 2nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. ini_set('display_errors', 1);
  2. require_once 'application/bootstrap.php';
  3.  
  4. require_once 'core/Model.php';
  5. require_once 'core/View.php';
  6. require_once 'core/Controller.php';
  7. require_once 'core/Route.php';
  8. Route::start();
  9.  
  10. RewriteEngine On
  11. RewriteCond %{REQUEST_FILENAME} !-f
  12. RewriteCond %{REQUEST_FILENAME} !-d
  13. RewriteRule .* index.php [L]
  14.  
  15. static function start()
  16. {
  17. $controller_name = 'Main';
  18. $action_name = 'Index';
  19.  
  20. $routes = explode('/', $_SERVER['REQUEST_URI']);
  21. var_dump($routes);
  22. if (!empty($routes[2])) {
  23. $controller_name = $routes[2];
  24. }
  25.  
  26. if (!empty($routes[3])) {
  27. $action_name = $routes[3];
  28. }
  29.  
  30. $model_name = 'Model' . $controller_name;
  31. $controller_name = 'Controller' . $controller_name;
  32. $action_name = 'action' . $action_name;
  33.  
  34. $model_file = $model_name . '.php';
  35. $model_path = "application/models/" . $model_file;
  36. if (file_exists($model_path)) {
  37. include "application/models/" . $model_file;
  38. }
  39. $controller_file = $controller_name . '.php';
  40. $controller_path = "application/controllers/" . $controller_file;
  41. if (file_exists($controller_path)) {
  42. include "application/controllers/" . $controller_file;
  43. } else {
  44. Route::ErrorPage404();
  45. }
  46.  
  47. $controller = new $controller_name;
  48. $action = $action_name;
  49.  
  50. print $controller_name;
  51. echo "<br/>";
  52. print $action;
  53.  
  54.  
  55. if (method_exists($controller, $action)) {
  56. $controller->$action();
  57. } else {
  58. Route::ErrorPage404();
  59. }
  60. }
  61.  
  62. function ErrorPage404()
  63. {
  64. print "trouble";
  65. $host = 'http://' . $_SERVER['HTTP_HOST'] . '/';
  66. header('HTTP/1.1 404 Not Found');
  67. header("Status: 404 Not Found");
  68. header('Location:' . $host . '404');
  69. }
Add Comment
Please, Sign In to add comment