/** * Start listen to routes */ public function start() { $this->url = $_SERVER['REQUEST_URI']; $method = $_SERVER['REQUEST_METHOD']; $this->route = new Route($method, $this->url, $this->routes); $entityName = $this->route->getController(); $modelName = 'App\\Models\\' . $entityName . 'Model'; $modelPath = 'application/models/' . $entityName . 'Model.php'; if (file_exists($modelPath)) { include $modelPath; } $controllerName = 'App\\Controllers\\' . $entityName . 'Controller'; $controllerPath = 'application/controllers/' . $entityName . 'Controller.php'; // include controller if (file_exists($controllerPath)) { include $controllerPath; } else { Router::ErrorResponse('Page not found.', 404); } $requestData = Request::getRequestParams(); // create controoler $controller = new $controllerName(new $modelName(), $requestData); $action = $this->route->getAction() . 'Action'; if (method_exists($controller, $action)) { // call controller action call_user_func_array(array($controller, $action), $this->route->getTokens()); } else { Router::ErrorResponse('Page not found.', 404); } }