[development] Re: [infrastructure] Drupal.org should have better URL aliases

Bèr Kessels ber at webschuur.com
Tue Dec 27 19:37:23 UTC 2005


Op dinsdag 27 december 2005 17:21, schreef Dries Buytaert:
> > This way we need no extra hooks, no extra variables, and no extra
> > memory. Or
> > hardly, anyway. While it saves a lot of code.
>
> Erm.  Does that imply that each page should be in the 'menu tree'?

No. Hence the %foo tokens. Similar to locale replacement

> How does the system knows that 'project/foo' is node 42 of type
> project, that 'blog/2005/12/27/hello_world' is node 69 of type blog,
> or that 'about' is node 1 of type page?  And vice versa, that node 42
> is 'project/foo', that node 69 is 'blog/2005/12/27/hello_world' or
> that node 1 is 'about'?

It does, because menu knows so. 'blog/2005/12/27/hello_world' Let me try to 
explain:). 
One way is rather easy:

blogfurls.module:
function blogfurls_menu() {
  $items[] = array('title' => 'blog thing',
      'original_path' => '/blog/%year/%month/%day/%title',
      'original_replace' => array('%year' =>'$obj->year', ..., '%title' => 
'$obj->title'), // NOTE '$obj->year' is a string! note the ' '.
      'callback' => 'blogfurls_show_blog',
...
 }

function blogfurls_show_blog() {
  global $menu
  $args['title'] = arg(4);
  $args['date'] = make_date_from_url(arg(1), ...,arg(3));  
  $node = node_load($args);
  return theme('node', $node);
}

The other part, is a bit harder to explain. And in fact, i have not yet 
figured out the details of how to do this in PHP: so here is the Rails 
code :p

ActionController::Routing::.... do |map|
  ...
  map.connect "blog/:year/:month/:day/:title" #in Ruby ":month/" is like the 
"$month/" in PHP
  	:controller		=> "blog" 
	:action		=> "show_date" #we call this callback, in drupal
	:requirements	=> {:year => /(19|20)\d\d/, 
			        :month => /[01]?\d/, etc ... an array with preg-stuff to filter out 
dates
done

now, RoRs smartness comes to play. and here is where i have n clue how to do 
this in drupal, yet.

@link = url_for(:day => "27") 
will return http://.../blog/2005/12/27 (the rest, is just figured out by 
sensible magic"
@link = url_for(:year => "2005") 
will return http://.../blog/2005/
nifteeey!

You see, that its url_for function is a bit more complex then our url feature. 
It does not take strings, but arguments. Maybe that direction is the key to 
sucess here?

> I don't see how we can save hooks, variables, memory and code.  Can
> you provide an example in pseudo-code that clarifies the workflow of
> (i) generating a page with clean URLs and (ii) loading a page based
> on a clean URL?

(i) Nothing, null, Voidness. we dont do anything on page generation! We should 
not do anything wrt url stuff on page generation. (exept some smarter cache 
generation, but that is totally off topic)

(ii) See above. The part where i have no clue yet :)


 [ Bèr Kessels | Drupal services www.webschuur.com ]


More information about the development mailing list