diff --git a/app/classes/router.php b/app/classes/router.php new file mode 100644 index 0000000..f600ee4 --- /dev/null +++ b/app/classes/router.php @@ -0,0 +1,38 @@ +routes[$pattern] = $callback; + } + + public function dispatch($url) { + // remove variables from url + $url = strtok($url, '?'); + + foreach ($this->routes as $pattern => $callback) { + if (preg_match('#^' . $pattern . '$#', $url, $matches)) { + // move any exact match + array_shift($matches); + return $this->invoke($callback, $matches); + } + } + + // if there was no match at all, return 404 + http_response_code(404); + echo '404 page not found'; + } + + private function invoke($callback, $params) { + list($controllerName, $methodName) = explode('@', $callback); +// $controllerClass = "\\App\\Controllers\\$controllerName"; + $controllerClass = "../pages/$pageName"; + $controller = new $controllerClass(); + call_user_func_array([$controller, $methodName], $params); + } + +} + +?> diff --git a/doc/.htaccess b/doc/.htaccess new file mode 100644 index 0000000..c958769 --- /dev/null +++ b/doc/.htaccess @@ -0,0 +1,14 @@ +RewriteEngine On + +# limit access to .htaccess + + Order Allow,Deny + Deny from all + + +# don't rewrite CSS, JS, etc. +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +# all other go to index.php +RewriteRule ^(.*)$ index.php?page=$1 [L,QSA] diff --git a/doc/config.apache b/doc/config.apache index 3f457f9..fa9727e 100644 --- a/doc/config.apache +++ b/doc/config.apache @@ -4,4 +4,9 @@ CustomLog \${APACHE_LOG_DIR}/jilo-web_access.log combined ErrorLog \${APACHE_LOG_DIR}/jilo-web_error.log + + + AllowOverride All + +