Honestly i dont know. I did this based on my poor knowledge. Maybe Ruud and others should review the code.
This is how it works (my idea):
mostly, access files contains
$page_id = 2;
Now, want to access page: http://www.WebsiteBaker.org/en/help/designer-guide/porting-an-existing-html-template.php
which is, as rewriten url http://www.WebsiteBaker.org/en/help/designer-guide/porting-an-existing-html-template
*(without .php, also note that there is no phisical file)
First I make array of links :
and i search _pages table in Database for the longest link, if it is not matched, i seach shorter one, and so one until it match something (if no match - redirect to error404 page)
create a list of required search fields for each modules:
example: for wysiwyg, code, form etc.., you only need $page_id to work (I found this info in phisical access files) , and for bakery you may need $item_id (when displaying specific item) or without item_id (when showing overview page), same for news page - you may need $post_id, $section_id etc , when displaying specific post, or without for overview.
Then when you match page and have its PAGE_ID, then search in _sections table from Database, and search for sections, and throw sections (module names) in array.
Then loop in array, if page has section wysiwyg, they just show $page_id, if page has section News, show $page_id.
Now, the catch (how it works):
you have url like: www.mysite.xy/latest/news/
1. chop links:
 /latest/news -matched, and stop.
it will match first link, and fetch $page_id for it.
we continue to see if there is something more interesting in url (like post's link)
we see that there is no match. and thats it.
but if you have url like: www.mysite.xy/latest/news/football/game-is-postponed/
1. chop links:
 /latest/news/football/game-is-postponed/ --- no match, continue
 /latest/news/football --------- no match, continue
 /latest/news ----- match. stop searching.
we get $page_id from this match, and we continue to see if there is something more interesting in url (like post's link)
from /latest/news/football/game-is-postponed/ we strip /latest/news so we have left /football/game-is-postponed
now we loop in _news_posts table to get best match (search longest link first) and we will match link and get $post_id and $section_id from database.
How to create links like /group-name/friendly-news-post-name urls, you can find in my first post.
same principles is for bakery.
So basicly in this one file, based on url, you only fetch parameters required for access files.
please test and give comments