1) It is better to implement something like:

<?php $route = new Routing(); $route->foo('/example', array( 'MainController' => 'example' ) ); ?> 

The first argument is an alias, obtained from the url, the second array, where it is indicated where to apply if the link coincided with the alias.

2) Or stored in the database, the field "link" and "alias", and with each page request, make a selection and show the link that matched.

3) Here's another option, Habré . There through xml. Can I use ini files?

Here I did not consider the option where the URL is broken into parts, and then, depending on the link, the controller, method, action is directly called ...

So, comrades, I ask you, as more experienced, which approach is better? If the options given by me are unsuccessful, please provide a more convenient and safer alternative :)

    1 answer 1

    No need to keep the rules in the database, it will create a large load on it. I advise you to see how it is done in Symfony 2 , it is very well implemented there. And the data format itself in which it will store everything is another matter. Someone in php arrays does it, someone in a json file. Generally in article from a habr everything is well described.