I’m following this tutorial from laracast(https://laracasts.com/series/php-for-beginners) and I’m at this episode(16 - Make a Router) in the series. Which shows how to build a basic router. I have done everthing to my knowledge as illustrated in the video, but I’m experiencing problems with building the router. I’m getting this error message:
Fatal error: Uncaught exception 'Exception' with message 'No routes define for this uri' in C:\wamp64\www\todo\core\Router.php on line 23 Exception: No routes define for this uri in C:\wamp64\www\todo\core\Router.php on line 23
How do I get passed this error? Here are my codes
routes.php:
$router->define([
'' => 'controllers/index.php',
'about' => 'controllers/about.php',
'contact' => 'controllers/contact.php'
]);
Router.php
class Router
{
protected $routes = [];
// this function defines our routes
public function define($routes)
{
# code...
$this->routes = $routes;
}
public function direct($uri){
if (array_key_exists($uri, $this->routes)) {
# code...
return $this->routes[$uri];
}
throw new Exception("No routes define for this uri");
}
}
Index.php
$database = require 'core/bootstrap.php';
$router = new Router;
require 'routes.php';
$uri = trim($_SERVER['REQUEST_URI'], '/');
require $router->direct($uri);
If you need more information inform me.
UPDATE This is my site structure in wampserver www folder: