[development] Re: [infrastructure] Drupal.org should have better
URL aliases
Bèr Kessels
ber at webschuur.com
Tue Dec 27 15:40:28 UTC 2005
Op dinsdag 27 december 2005 10:30, schreef Dries Buytaert:
> I think WP doesn't use an intermediate table that contains (source
> URL, destination URL)-tuples. Instead, it directly translates the
> URL to a database query that looks up the post.
I will try to explain the RoR way of doing this. ITs absolutely brillant in ts
simplicity. really! And it has absolutely no performance penalty. (but then
again, php != Ruby)
RoR has, to start with a much cleaner default url structure:
example.com/say/hello <= example.com/controller/action
For drupal that would be:
example.com/say/hello <= example.com/module/function
We currently hardwire this in hook_menu.
Now, I must add here, that due to RoRs 'build on top of existing stuff' you
get all sorts of actions for free. my_controller/list, my_controller/add etc.
The next step, obviously is to map these to new actions: RoR calls this
routing. We call it hook_menu. In fact, they are so similar in nature, that i
suspect the menu author had a peek at RoR :)
So, the good news, is that in RoR you need nothing more. The URL generation in
RoR uses these maps to make its urls. That is clean, simlpe and fits well in
the philosophy 'don't repeat yourself' (aka no-copy-paste-coding).
I suggest we adapt this mechanism for Drupal in Core. Then we can do all our
path/url mapping in code. Code we already have. Variables that are already
built and loaded ($menu).
What we cannot do, is hand-editing ni our GUIS.
But then I ask myself: If i have pathauto, which does all the mapping in the
code, then why the ** do i need to store that in a database, other then for
some caching?
Hence I suggest we ignore the hand-coded urlmapping for now. And focus on this
menu-mapping. After that, we can just use our current database mapping
(path.module), through this menu mechanism, to handle those few hand-edited
paths. Or is there anyone out there, who maintains over a few hundred
hand-edited path aliases? and if so, is that because you want to, or because
you lack a [book-structure-mapper|taxonomy-mapper|username-mapper] ?
Some pseudoish flowchart code:
function hook_menu() {
$menu_item[] = array(title => 'foo', original_path => 'bar/%d',
original_replace => '$object->oid', 'map' => 'bar/%s', 'map_replace' =>
'urlencode($obj->name)';
//replace is to know what to replace the sprintf tokens in a path
}
....
function create_path($path, $object) {
global $menu
$mid = menu_find_by_path('')
$original_path = sprint_f($menu[$mid][original_path], $menu[$mid]
[original_replace])
$new_path = sprint_f($menu[$mid][map_path], $menu[$mid][map_replace])
return _path_str_replace($path, $menu[$mid]);
}
This way we need no extra hooks, no extra variables, and no extra memory. Or
hardly, anyway. While it saves a lot of code.
Bèr 'who wants to think this trough more thoroughly, though' Kessels
--
| Bèr Kessels | webschuur.com | website development |
| Jabber & Google Talk: ber at jabber.webschuur.com
| http://bler.webschuur.com | http://www.webschuur.com |
More information about the development
mailing list