Help with a question. I have been suffering for 3 days already. Why the routs do not work in any way.

Here is the site structure

project ---------model ---------view ----------index.php ---------controller ----------IndexController.php ----------AboutController.php ----------FreeTemplateController.php ----------ContactController.php ---------config ----------router.php ---------.htaccess ---------index.php 

.htaccess

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 

project / index.php

  ini_set('display_errors',1); error_reporting(E_ALL); function autoload($class) { require_once "controller/" . ucfirst($class) . "Controller.php"; } spl_autoload_register("autoload"); require_once("config/router.php"); $router = new Router(); $router->addRoutes(); 

config / router.php

  class Router { private $url; private $routes = array( "index" , "about", "freeТemplate", "contact" ); private function checkUrl($data) { $data = trim($data); $data = htmlspecialchars($data); return $data; } public function addRoutes() { if (!empty($_GET["url"])) { $this->url = $this->checkUrl($_GET["url"]); foreach ($this->routes as $key) { if (preg_match("~$key~" , $this->url)) { $controller = ucfirst($key). "Controller"; $controllerFile = "controller/" . $controller . ".php"; if (file_exists($controllerFile)) { include_once($controllerFile); } } } } else { if(empty($_GET["url"])) { require_once("controller/IndexController.php"); } } } } 

controller / IndexController.php

 class IndexController { public function actionIndex() { require_once("view/index.php"); return true; } } $index = new AboutController(); $index->actionIndex(); 

view / index.php

 print "Hello I am Index Page"; 

Thank you in advance

    0