"Configuring Routes and URL Resolution for Files in a Controllers Folder

41 Views Asked by At

I'm encountering a problem while learning php. In fact I'm trying to define the routes to access my different pages. And I have 3 of them. I have written an index file which is my main file that will allow me to access the right page via the right url ($_SERVER['REQUEST_URI'] === '/php/about' for example). But the problem being that my 3 files are in my controllers folder, wampserver logically tells me that it can't find its files when I do 'php/about' but when I do 'php/controllers/about' or 'php/controllers/contact'. So basically, how do I solve this problem?

i tried to change it to '/tuto-php/controllers/contact' but when i put 'tuto-php/contact' it says not found

/tuto-php
│
├── controllers
│   ├── about.php
│   ├── contact.php
|   ├── index.php
|── views
    ├── partials
        ├── banneer.php
        ├── nav.php
        ├── footer.php
        ├── head.php
    ├── about.view.php
    ├── contact.view.php
    ├── index.view.php
├── functions.php
├── index.php


<?php
//var_dump($_SERVER['REQUEST_URI']);


if ($url === '/tuto-php/') {
    require 'controllers/index.php';
} else if ($url ===  '/tuto-php/contact/') {
    require 'controllers/contact.php';
} else if ($url === '/tuto-php/about/') {
    require 'controllers/about.php';
}
0

There are 0 best solutions below