fork download
  1. <?php
  2.  
  3. require_once 'app/core/routeconfig.php';
  4. require_once 'app/core/route.php';
  5.  
  6. $route = new Route($routes);
  7. $route -> Run();
  8. ?>
  9.  
  10. <?php
  11.  
  12. class Route{
  13.  
  14. public $any = '([A-Za-z]+)';
  15. private $num = '([0-9]+)';
  16. public $controller;
  17. public $action;
  18. public $params = array();
  19. public $routes;
  20.  
  21.  
  22. public function __construct($routes) {
  23. $this->routes = $routes;
  24. }
  25.  
  26. function getUrl(){
  27.  
  28. return rtrim($_SERVER['REQUEST_URI'], '/');
  29.  
  30. }
  31.  
  32. function getRoute(){
  33. $i = 0;
  34.  
  35. foreach ($this->routes as $route){
  36.  
  37. $pattern = $route['pattern'];
  38. $pattern = str_replace(':any', $this->any, $pattern);
  39. $pattern = str_replace(':num', $this->num, $pattern);
  40.  
  41. //get uri
  42. $uri = $this->getUrl();
  43.  
  44. if(preg_match('#^'.$pattern.'$#', $uri)){
  45.  
  46. $this->controller = $route['path']['controller'];
  47. $this->action = $route['path']['action'];
  48. if(!empty($route[$i]['path']['params'])){
  49. foreach ($route[$i]['path']['params'] as $param => $value) {
  50.  
  51. $params = array($param => $value);
  52. }
  53. }
  54.  
  55. break;
  56.  
  57. } $i++;
  58. }
  59. return array($this->controller, $this->action);
  60. }
  61.  
  62. public function Run(){
  63. $route = $this->getRoute();
  64. $controller = $route[0];
  65. $action_name = 'Action_'.$route[1];
  66. $controller_name = $this->connectionFile($controller);
  67.  
  68. $controller = new $controller_name;
  69. $controller -> $action_name();
  70. }
  71.  
  72. function connectionFile($controller){
  73.  
  74. $this->controller = $controller;
  75.  
  76. $controller_name = 'Controller_'.$controller;
  77. $controller_file = strtolower($controller_name).'.php';
  78. $model_name = 'Model_'.$controller;
  79. $model_file = strtolower($model_name).'.php';
  80.  
  81. if(file_exists('app/controllers/'.$controller_file)){
  82. include 'app/controllers/'.$controller_file;
  83. }else{
  84.  
  85. }
  86.  
  87. if(file_exists('app/models/'.$model_file)){
  88. include 'app/models/'.$model_file;
  89. }
  90.  
  91. return $controller_name;
  92. }
  93. }
Runtime error #stdin #stdout #stderr 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Warning:  require_once(app/core/routeconfig.php): failed to open stream: No such file or directory in /home/keUQsi/prog.php on line 3
PHP Fatal error:  require_once(): Failed opening required 'app/core/routeconfig.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/keUQsi/prog.php on line 3