Commit 7ac11f2e authored by Taddeus Kroes's avatar Taddeus Kroes

Updated docs for Router.

parent af804e03
...@@ -13,14 +13,41 @@ namespace BasicWeb; ...@@ -13,14 +13,41 @@ namespace BasicWeb;
require_once 'base.php'; require_once 'base.php';
/** /**
* A Router is used to call a handler function with corresponding to an URL.
* *
* Simple example: a website with the pages 'home' and 'contact'.
* <code>
* function home() {
* return 'This is the home page.';
* }
*
* function contact() {
* return 'This is the contact page.';
* }
*
* $router = new Router(array(
* '/home' => 'home',
* '/contact' => 'contact'
* ));
* $response = $router->call_handler('/home'); // 'This is the home page.'
* $response = $router->call_handler('/contact'); // 'This is the contact page.'
* </code>
* *
* You can use regular expression patterns to specify an URL. Any matches are
* passed to the handler funtion as parameters:
* <code> * <code>
* function page($pagename) {
* return "This is the $pagename page.";
* }
* *
* $router = new Router(array(
* '/(home|contact)' => 'page'
* ));
* $response = $router->call_handler('/home'); // 'This is the home page.'
* $response = $router->call_handler('/contact'); // 'This is the contact page.'
* </code> * </code>
* *
* @package BasicWeb * @package BasicWeb
* @todo Example
*/ */
class Router extends Base { class Router extends Base {
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment