php-doc-en/reference/yaf/yaf_route_regex/construct.xml
Xinchen Hui d980c7d0fe add example of named capture group
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@339562 c90b9560-bf6c-de11-be94-00142212c4b1
2016-07-05 07:03:59 +00:00

229 lines
6.6 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<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>Yaf_Route_Regex constructor</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <methodname>Yaf_Route_Regex::__construct</methodname>
<methodparam><type>string</type><parameter>match</parameter></methodparam>
<methodparam><type>array</type><parameter>route</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>map</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>verify</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>reverse</parameter></methodparam>
</methodsynopsis>
<para>
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>match</parameter></term>
<listitem>
<para>
A complete Regex pattern, will be used to match a request uri, if
doesn't matched, <classname>Yaf_Route_Regex</classname> will return
&false;.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>route</parameter></term>
<listitem>
<para>
When the match pattern matches the request uri,
<classname>Yaf_Route_Regex</classname> will use this to decide which
m/c/a to routed.
</para>
<para>
either of m/c/a in this array is optianl, if you don't assgian a
specific value, it will be routed to default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>map</parameter></term>
<listitem>
<para>
A array to assign name to the captrues in the match result.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>verify</parameter></term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>reverse</parameter></term>
<listitem>
<para>
a string, used to assemble url, see
<methodname>Yaf_Route_Regex::assemble</methodname>.
<note>
<para>
this parameter is introduced in 2.3.0
</para>
</note>
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>Yaf_Route_Regex</function>example</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Add a regex route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
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(as of 2.3.0)</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 and named capture ground(as of 2.3.0)</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/(?<name>[^/]+)/([^/])+#i", //match request uri leading "/product"
array(
'controller' => ":name", // route to :name,
// which is named capture group 'name' in the match result as controller name
),
array(
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
*/
$config = array(
"name" => array(
"type" => "regex", //Yaf_Route_Regex route
"match" => "#(.*)#", //match arbitrary request uri
"route" => array(
'controller' => "product", //route to product controller,
'action' => "dummy", //route to dummy action
),
"map" => array(
1 => "uri", // now you can call $request->getParam("uri")
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
]]>
</programlisting>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>Yaf_Router::addRoute</methodname></member>
<member><methodname>Yaf_Router::addConfig</methodname></member>
<member><classname>Yaf_Route_Static</classname></member>
<member><classname>Yaf_Route_Supervar</classname></member>
<member><classname>Yaf_Route_Simple</classname></member>
<member><classname>Yaf_Route_Rewrite</classname></member>
<member><classname>Yaf_Route_Map</classname></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->