F
F
fso2013-09-27 20:30:36
CMS
fso, 2013-09-27 20:30:36

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){  /* */ });

2) the same as item 1. but loading regular expressions and controller names from the database
3) fetching the controller name from the database by exact match
$ctrlName = $DB->selectCell("SELECT `ctrlName` FROM `Pages` WHERE `URL` LIKE ?", $_SERVER['REQUEST_URI']);

4) the same but using a GET parameter
$ctrlName = $DB->selectCell("SELECT `ctrlName` FROM `Pages` WHERE `ID`=?d", $_GET['page_id']);

5) parsing the url into parts into an array
 /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

Tell me more?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
raskumandrin, 2013-09-27
@raskumandrin

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

N
Nikolai Turnaviotov, 2013-09-27
@foxmuldercp

in asp.net mvc it is also interesting that the routes are written. regarding the actual structure of the project files-

N
Nazar Mokrinsky, 2013-09-27
@nazarpc

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"
]

If the module has an admin/API, the corresponding prefixes are added before the module name.

V
Vadim, 2013-10-02
@vshemarov

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 question

Ask a Question

731 491 924 answers to any question