URL generation for (Multi)URLDispatcher

Bug #121560 reported by Sander van Schouwenburg (Sandworm)
4
Affects Status Importance Assigned to Milestone
Anewt
New
Undecided
Unassigned

Bug Description

(Multi)URLDispatcher should have a generate_url() function to create the urls which can be dispatched by the given url dispatcher.

Revision history for this message
Sander van Schouwenburg (Sandworm) (sander-sinaasappel) wrote :

Attached are ModuleDispatcher and BaseDispatcher which are extensions to MultiURLDispatcher and URLDispatcher respectively.

The generate_url() functions probably work as expected. $mymultiurldispatcher->generate_url('mymodule', 'mycommand', array('id' => 5)) returns $mydispatcher->generate_url('mycommand, array('id' => 5)) prefixed with the prefix for 'mymodule', where $mydispatcher is an instance of the class which is mapped to 'mymodule'.
$mydispatcher->generate_url('mycommand, array('id' => 5)) returns an url part for the first mapping with command 'mycommand' and if it contains and ':id' part it will be substituted by 5. It returns a trailing slash depending on the 'force-trailing-slash' option.

I expect that this code can quite safely be inserted in the original MultiURLDispatcher and URLDispatcher classes. Only note that on line 50 the line
  $dispatcher = BaseDispatcher::get_instance($class_name);
must be replaced with:
  $dispatcher = URLDispatcher::get_instance($class_name);

KNOWN BUGS:
- When you want to generate the url of a certain module, the dispatcher for that module must be loaded.
- When you have multiple mappings to the same command name, the first one found will be used, regardless of possible different arguments.
- The arguments to the urls are not checked for existance.
  i.e.: /item/:id/ will be resolved to '/item/'.$params['id'].'/' regardless of whether $params['id'] actually is set.

Revision history for this message
wouter bolsterlee (wbolster) wrote :

This code is largely obsoleted by the new AnewtURLDispatcher class which has a totally different API and structure (much better, imho, though). The feature request this bug is about still stands, though. I'm just not sure about a clean API for this.

tags: added: urldispatcher
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.