From 2783e4a10bc8db85313883090005f5fc7ff10900 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Mon, 9 Dec 2013 10:33:21 +0000 Subject: [PATCH] Update example for routes git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@332313 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/yaf/yaf_route_regex/construct.xml | 30 ++++++++++-- reference/yaf/yaf_route_rewrite/construct.xml | 48 +++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/reference/yaf/yaf_route_regex/construct.xml b/reference/yaf/yaf_route_regex/construct.xml index e243d4b221..8daefb5a49 100644 --- a/reference/yaf/yaf_route_regex/construct.xml +++ b/reference/yaf/yaf_route_regex/construct.xml @@ -4,7 +4,7 @@ Yaf_Route_Regex::__construct - The __construct purpose + Yaf_Route_Regex constructor @@ -17,11 +17,9 @@ arrayverify - + - &warn.undocumented.func; - @@ -107,6 +105,30 @@ <function>Yaf_Route_Regex</function>example getRouter()->addRoute("name", + new Yaf_Route_Regex( + "#^/product/([^/]+)/([^/])+#i", //match request uri leading "/product" + array( + 'controller' => ":name", // route to :name, which is $1 in the match result as controller name + ), + array( + 1 => "name", // now you can call $request->getParam("name") + 2 => "id", // to get the first captrue in the match pattern. + ) + ) + ); +?> +]]> + + + + <function>Yaf_Route_Regex</function>example + +Yaf_Route_Rewrite will return &false;. + + you can use :name style to name segments matched. and use * to match + rest segments. + @@ -144,6 +148,50 @@ array( "module" => "index", //(default) ) +/** + * and request parameters: + */ +array( + "id" => 22, +) +]]> + + + + <function>Yaf_Route_Rewrite</function>example + + array( + "type" => "rewrite", + "match" => "/user-list/:a/:id", //match only /user-list/* + "route" => array( + 'controller' => "user", //route to user controller, + 'action' => ":a", //route to :a action + ), + ), + ); + Yaf_Dispatcher::getInstance()->getRouter()->addConfig( + new Yaf_Config_Simple($config)); +?> +]]> + + &example.outputs.similar; + + "user", + "action" => "list", + "module" => "index", //(default) +) + /** * and request parameters: */