PHP routing system altorouter not working

201 Views Asked by At

I'm just developing a website with PHP and for routing, I decided not to build the whole system myself anymore, then I chose altorouter/altorouter. So here's my site tree my site tree

And here's what my index.php looks like

<?php

define('WEBROOT', __DIR__);

define('TARGET_PATH', WEBROOT.'/contents');


require 'vendor/autoload.php';

$router = new AltoRouter();

$router->setBasePath('/kpitalis.com/');

require_once 'config/routes.php';

$match = $router->match();

$target = $match['target'];
$params = $match['params'];


if (is_array($match)) {
    if (is_callable($match['target'])) {
        call_user_func_array($target, $params);
    } else {
        ob_start();
        require TARGET_PATH."/{$target}.php";
        $pageView = ob_get_clean();
    }
    require TARGET_PATH."/frame/layout.php";
} else {
    require TARGET_PATH."/error.php";
}

My routes' file routes.php looks like:

<?php

$router->map('GET', '/', 'home', 'home');
$router->map('GET', '/contact', 'contact', 'contact');
$router->map('GET', '/about', 'about', 'about');
$router->map('GET', '/achievements', 'achievements', 'achievements');
$router->map('GET', '/achievements/[*:slug]', 'achievements', 'achievement');
$router->map('GET', '/projects', 'projects', 'projects');
$router->map('GET', '/projects/[*:slug]', 'projects', 'project');
$router->map('GET', '/news', 'news', 'news');
$router->map('GET', '/news/[*:slug]', 'news', 'single_news');

?>

And my .htaccess

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

The thing is I can get routes when I run le PHP sel-server but can't my css and javascipt files (I say Ok, I can fix it later) Now I'm trying to see how it works on my localhost but all I can reach is the error page error.php

What am I missing?

0

There are 0 best solutions below