Public Member Functions | |
| MultiURLDispatcher () | |
| Constructor for a new MultiURLDispatcher. | |
| add_prefix ($prefix, $module_name=null, $class_name) | |
| Add a prefix to the list of prefix mappings. | |
| dispatch ($url=null) | |
| Dispatch an URL to the correct handlers. | |
| setup_mappings () | |
| Set up the url mappings. | |
| load_module ($module_name) | |
| Load a module specified in a prefix mapping. | |
Private Attributes | |
| $prefix_to_dispatcher_mapping | |
| URL maps. | |
This class is useful for larger sites composed of different 'modules', all running in a different url prefix ('url namespace'). An example: You run several news pages (view item, archive, ...) at urls starting with '/news'. You want to have all news-related dispatchin code into a separate dispatcher class, located in a file of its own.
To use this class, you should override this class and implement setup_mappings() and optionally load_module().
Your setup_mappings() method should set the 'default-class' property to the name of the default dispatcher class to use. You may also set the 'default-module' property (see below). Additionally, this methods should contain calls to add_prefix to define which module/class name should be used for the supplied url prefix.
Override and implement the load_module() method if the dispatcher class names used in your add_prefix() calls are not yet available when the dispatcher is invoked. A common and simple implementation of the load_module() should make sure the class name is loaded, e.g. by including the right file. (Hint: use a foo_include() function; see create_include_function() for details.)
Note that the dispatchers will have the url prefix stripped off when called! Coming back to the news example, this means that the url maps of your news UrlDispatcher class should not include the '/news' part in the urlmaps.
Definition at line 56 of file multi.lib.php.
| MultiURLDispatcher::add_prefix | ( | $ | prefix, | |
| $ | module_name = null, |
|||
| $ | class_name | |||
| ) |
Add a prefix to the list of prefix mappings.
Call this method from your setup_mappings() method.
| $prefix | The url prefix to match | |
| $module_name | The module name passed to load_module() (optional, specify null if you don't need it) | |
| $class_name | The class name of the dispatcher to instantiate and invoke. |
Definition at line 85 of file multi.lib.php.
| MultiURLDispatcher::dispatch | ( | $ | url = null |
) |
Dispatch an URL to the correct handlers.
See the documentation on URLDispatcher::dispatch() for more information on the parameters.
| $url | The url to dispatch (optional, defaults to null). |
Definition at line 107 of file multi.lib.php.
| MultiURLDispatcher::setup_mappings | ( | ) |
Set up the url mappings.
You must override this method.
Definition at line 154 of file multi.lib.php.
| MultiURLDispatcher::load_module | ( | $ | module_name | ) |
Load a module specified in a prefix mapping.
Override this method to load needed dispatcher classes on demand.
| $module_name | Name of the module to load (string) |
Definition at line 167 of file multi.lib.php.
1.5.9