Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jollyjaywhiskers's avatar

Stuck on "The PHP Practitioner" Episode 16

I'm aware that this question has been asked at least 2 times so far, but I've yet to find an answer that works for me and it's starting to really get frustrating as I've been stuck on this for 2 days watching the video over and over again trying to figure out where my code's gone wrong.

I'm currently using XAMPP on windows and cannot progress because it seems as if either the router cannot get access to the routes.php file, or it's some sort of htaccess issue.

I've tried hardcoding the URI to the direct() method in my index.php file and that works fine, but using the var $uri breaks my code and I cannot progress.

Here's what's in my routes file:

<?php 

$router->define([
    ''=>'controllers/index.php',
    'about'=>'controllers/about.php',
    'about/culture'=>'controllers/about-culture.php',
    'contact'=>'controllers/contact.php'
]);

Here's my router.php file:

<?php

class Router
{
    protected $routes = [];
    public function define($routes)
    {
        $this->routes = $routes;
    }

    public function direct($uri)
    {
        if (array_key_exists($uri, $this->routes)){
            return $this->routes[$uri];
        } 
            
        throw new Exception("Undefined route for this URI");
        
    }
}

and here's my index.php file

<?php

$query = require 'core/bootstrap.php';


$router = new Router;

require 'routes.php';

$uri = trim($_SERVER['REQUEST_URI'], '/');

require $router->direct($uri);

for what it's worth, here's the .htaccess file:

RewriteEngine On
RewriteBase /laracasts/PHP/
RewriteRule ^.*$ index.php [END]

Any help would be greatly appreciated. I've been pulling hair and teeth out trying to figure this out.

EDIT: after var_dump-ing the URI, I noticed that they were showing as "laracasts/PHP" (index), "latacasts/PHP/about" (/about) and so on. It prompted me to try adding "laracasts/PHP" to my routes file before the actual key just to see if that works. Unfortunately, it still doesn't work.

0 likes
1 reply

Please or to participate in this conversation.