My code is really straight forward but the problem is whenever I click on an anchor tag
it will automatically append to the url path resulting in a page that does not exist.
For example
<li> <a href="blog/tag?cat=<?= $singleTag['id'];?>"
class="d-flex text-capitalize">
<p><?= $singleTag['name']; ?></p>
</a> </li>
It will assume that I'm trying to navigate to
blog/blog/tag?cat=something
I really don't know where the first /blog
came from I looked into other answers and they were suggesting
to add // dobule back slashes infront of the link but that will not work since I'm trying to refer to a local file.
My routes file
<?php
$router->get('','controllers/index.php');
$router->get('about','controllers/about.php');
$router->get('contact','controllers/contact.php');
$router->get('events','controllers/events.php');
$router->get('event/detail','controllers/event-detail.php');
$router->get('news','controllers/news.php');
$router->get('news/detail','controllers/news-detail.php');
$router->get('members','controllers/members.php');
$router->get('blog','controllers/blog.php');
$router->get('blog/detail','controllers/single-blog.php');
$router->get('blog/tag','controllers/all-blog-tags.php');
$router->get('oops','controllers/error-page.php'); ?>
My request class
<?php
class Request
{
public static function uri()
{
// dd(parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY));
$urlQuery = parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY);
if (strpos($urlQuery, 'slug=') !== false) {
$GLOBALS['slug'] = $urlQuery;
}
if (strpos($urlQuery, 'cat=') !== false) {
$GLOBALS['cat'] = $urlQuery;
}
return ( trim(parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH),'/'));
}
public static function method()
{
return ($_SERVER['REQUEST_METHOD']);
}
} ?>
My router class
<?php
class Request
{
public static function uri()
{
// dd(parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY));
$urlQuery = parse_url($_SERVER['REQUEST_URI'],PHP_URL_QUERY);
if (strpos($urlQuery, 'slug=') !== false) {
$GLOBALS['slug'] = $urlQuery;
}
return ( trim(parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH),'/'));
}
public static function method()
{
return ($_SERVER['REQUEST_METHOD']);
}
}