Update example for routes

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@332313 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Xinchen Hui 2013-12-09 10:33:21 +00:00
parent 1453847230
commit 2783e4a10b
2 changed files with 74 additions and 4 deletions

View file

@ -4,7 +4,7 @@
<refentry xml:id="yaf-route-regex.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Yaf_Route_Regex::__construct</refname>
<refpurpose>The __construct purpose</refpurpose>
<refpurpose>Yaf_Route_Regex constructor</refpurpose>
</refnamediv>
<refsect1 role="description">
@ -17,11 +17,9 @@
<methodparam choice="opt"><type>array</type><parameter>verify</parameter></methodparam>
</methodsynopsis>
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@ -107,6 +105,30 @@
<title><function>Yaf_Route_Regex</function>example</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Use match result as MVC name
*/
Yaf_Dispatcher::getInstance()->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.
)
)
);
?>
]]>
</programlisting>
</example>
<example>
<title><function>Yaf_Route_Regex</function>example</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Add a regex route to Yaf_Router route stack by calling addconfig

View file

@ -31,6 +31,10 @@
doesn't matched, <classname>Yaf_Route_Rewrite</classname> will return
&false;.
</para>
<para>
you can use :name style to name segments matched. and use * to match
rest segments.
</para>
</listitem>
</varlistentry>
<varlistentry>
@ -144,6 +148,50 @@ array(
"module" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"id" => 22,
)
]]>
</screen>
</example>
<example>
<title><function>Yaf_Route_Rewrite</function>example</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Add a rewrite route use match result as m/c/a name
*/
$config = array(
"name" => 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));
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
/* for http://yourdomain.com/user-list/list/22
* route will result in following values:
*/
array(
"controller" => "user",
"action" => "list",
"module" => "index", //(default)
)
/**
* and request parameters:
*/