Answer the question
In order to leave comments, you need to log in
Ways of "routing" pages in CMS / Frameworks
Hello all!
I was puzzled to collect all the approaches with the help of which, in various CMS and frameworks, the url is parsed and the definition of which controller to work is carried out.
Offhand they recall:
0) folder structure - the necessary structure is created and the necessary controller is placed in each directory
1) with rewrite, the use of regular expressions is static in the code:
$Router->addRoute("/news/[0-9]+", function($params){ /* */ });
$ctrlName = $DB->selectCell("SELECT `ctrlName` FROM `Pages` WHERE `URL` LIKE ?", $_SERVER['REQUEST_URI']);
$ctrlName = $DB->selectCell("SELECT `ctrlName` FROM `Pages` WHERE `ID`=?d", $_GET['page_id']);
/pages/news/all/1/ => array('pages', 'news', 'all', '1')
and a selection from the base of this path, that is, something$Pages = $DB->select("SELECT * FROM `Pages` WHERE `URL` IN (?a)", array('pages', 'news', 'all', '1'));
with hierarchy check Answer the question
In order to leave comments, you need to log in
Your first option, slightly modified - wrapping regular expressions in placeholders (I have not seen the use of the translation "placeholders"), which are much more convenient to work with:
mojolicio.us/perldoc/Mojolicious/Guides/Routing#Routes
in asp.net mvc it is also interesting that the routes are written. regarding the actual structure of the project files-
I use the name of the module as the first element, and then the json structure of the form:
[
"latest_posts",
"section",
"post",
"tag",
"new_post",
"edit_post",
"drafts"
]
The first part of the URL path (for example, in site.com/page it is /page) corresponds to the class of the same name with a given prefix (for example, ControllerPage), but you can assign any other class in the site config. And the desired class is loaded by the autoloader when it twitches.
There is a default handler method inside the class, but you can use a regular expression to assign different handlers for different URLs (for site.com/page/add - one, for site.com/page/show/123 - another, etc.) .
It turns out both simple and flexible
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question