Problem with routes in php mvc

-2

I'm starting with PHP following the MVC pattern and I'm doing a website to manage products. The problem I have is that I call the controllers from different sites on the web and this generates problems for me as far as the urls. For example, I have a class, driver and view related to the products, and apart I also call the controller Products from the index.php and it gives me failures. If someone has had the same problem and / or can give me a little advice on how to use the routes in MVC, I would be very grateful. Thank you. I leave the files here: - Project structure:

  • Dirs.php:

  • Index.php, I make the call to the controller, here there is no error:

  • Noticias.php, which also calls the controller to show news, as in the index.php, but since they are not in the same directory, I get this error:

  • And finally the newsController.php file, which calls the newsModel.php file to instantiate the News class:

  • And the class noticiaModel.php, which calls the class conexion.php:

In short, the problem I have is that I try to call the controller from the index and from another file in the view, and I get an error. I hope someone can help me a little because I do not know what to do. Many thanks in advance colleagues.

    
asked by user8584896 08.09.2018 в 19:58
source

1 answer

0

The error is in newsModel.php since you are including with a relative path the file dirs.php that is in another directory as if it were in it. You have put ./dirs.php when it should be ../dirs.php since newsModel.php is inside the Models folder although the best option is to use a PHP constant that refers to the directory where the current file is:

include_once(__DIR__.'../dirs.php')
    
answered by 10.09.2018 / 13:18
source