pHP 应用程序的小型库
Below is the list of functions provided by dispatch.
…Here's a sample of how you'd usually use them in an app.
…Once dispatch(...) is called, it will try to match the current request to any
of the mapped routes via route(...). When it finds a match, it will then do the
following sequence:
bind(...)apply(...)Because of this sequence, it means that any transformations done by bind(...)
mappings will have already updated the values inside the $params array that's
forwarded down the execution chain.
If you are running Dispatch as a stanalone PHP file, either on the root path or not (eg: path/to/search.php), this can cause errors with path matching.
You can use the DISPATCH_PATH_PREFIX global to mimic URL rewriting used in other libraries;
<?php
// file: path/to/search.php
// NOTE: this must be defined before calling the dispatch.php file
define('DISPATCH_PATH_PREFIX', '/path/to/search.php');
require __DIR__ . '/dispatch.php';
route('GET', '/testing', function() {
echo "test page on subpath " . $_SERVER['REQUEST_URI'];
});
dispatch();MIT
暂无开放 Issues,或尚未同步最近议题。