<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Yaf_Route_Regex constructor</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.yaf-route-regex.html">Yaf_Route_Regex</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-route-regex.route.html">Yaf_Route_Regex::route</a></div> <div class="up"><a href="class.yaf-route-regex.html">Yaf_Route_Regex</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="yaf-route-regex.construct" class="refentry"> <div class="refnamediv"> <h1 class="refname">Yaf_Route_Regex::__construct</h1> <p class="verinfo">(Yaf >=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Route_Regex::__construct</span> — <span class="dc-title">Yaf_Route_Regex constructor</span></p> </div> <div class="refsect1 description" id="refsect1-yaf-route-regex.construct-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><strong>Yaf_Route_Regex::__construct</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$match</code></span> , <span class="methodparam"><span class="type">array</span> <code class="parameter">$route</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$map</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$verify</code></span> ]] )</div> <p class="para rdfs-comment"> </p> </div> <div class="refsect1 parameters" id="refsect1-yaf-route-regex.construct-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <span class="term"><em><code class="parameter">match</code></em></span> <dd> <p class="para"> A complete Regex pattern, will be used to match a request uri, if doesn't matched, <a href="class.yaf-route-regex.html" class="classname">Yaf_Route_Regex</a> will return <strong><code>FALSE</code></strong>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">route</code></em></span> <dd> <p class="para"> When the match pattern matches the request uri, <a href="class.yaf-route-regex.html" class="classname">Yaf_Route_Regex</a> will use this to decide which m/c/a to routed. </p> <p class="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. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">map</code></em></span> <dd> <p class="para"> A array to assign name to the captrues in the match result. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">verify</code></em></span> <dd> <p class="para"> </p> </dd> </dt> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-yaf-route-regex.construct-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> </p> </div> <div class="refsect1 examples" id="refsect1-yaf-route-regex.construct-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-4164"> <p><strong>Example #1 <span class="function"><strong>Yaf_Route_Regex()</strong></span>example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">/**<br /> * Add a regex route to Yaf_Router route stack<br /> */<br /> </span><span style="color: #0000BB">Yaf_Dispatcher</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">()-></span><span style="color: #0000BB">getRouter</span><span style="color: #007700">()-></span><span style="color: #0000BB">addRoute</span><span style="color: #007700">(</span><span style="color: #DD0000">"name"</span><span style="color: #007700">,<br /> new </span><span style="color: #0000BB">Yaf_Route_Regex</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">"#^/product/([^/]+)/([^/])+#"</span><span style="color: #007700">, </span><span style="color: #FF8000">//match request uri leading "/product"<br /> </span><span style="color: #007700">array(<br /> </span><span style="color: #DD0000">'controller' </span><span style="color: #007700">=> </span><span style="color: #DD0000">"product"</span><span style="color: #007700">, </span><span style="color: #FF8000">//route to product controller,<br /> </span><span style="color: #007700">),<br /> array(<br /> </span><span style="color: #0000BB">1 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"name"</span><span style="color: #007700">, </span><span style="color: #FF8000">// now you can call $request->getParam("name")<br /> </span><span style="color: #0000BB">2 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"id"</span><span style="color: #007700">, </span><span style="color: #FF8000">// to get the first captrue in the match pattern.<br /> </span><span style="color: #007700">)<br /> )<br /> );<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-4165"> <p><strong>Example #2 <span class="function"><strong>Yaf_Route_Regex(as of 2.3.0)()</strong></span>example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">/**<br /> * Use match result as MVC name<br /> */<br /> </span><span style="color: #0000BB">Yaf_Dispatcher</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">()-></span><span style="color: #0000BB">getRouter</span><span style="color: #007700">()-></span><span style="color: #0000BB">addRoute</span><span style="color: #007700">(</span><span style="color: #DD0000">"name"</span><span style="color: #007700">,<br /> new </span><span style="color: #0000BB">Yaf_Route_Regex</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">"#^/product/([^/]+)/([^/])+#i"</span><span style="color: #007700">, </span><span style="color: #FF8000">//match request uri leading "/product"<br /> </span><span style="color: #007700">array(<br /> </span><span style="color: #DD0000">'controller' </span><span style="color: #007700">=> </span><span style="color: #DD0000">":name"</span><span style="color: #007700">, </span><span style="color: #FF8000">// route to :name, which is $1 in the match result as controller name<br /> </span><span style="color: #007700">),<br /> array(<br /> </span><span style="color: #0000BB">1 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"name"</span><span style="color: #007700">, </span><span style="color: #FF8000">// now you can call $request->getParam("name")<br /> </span><span style="color: #0000BB">2 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"id"</span><span style="color: #007700">, </span><span style="color: #FF8000">// to get the first captrue in the match pattern.<br /> </span><span style="color: #007700">)<br /> )<br /> );<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-4166"> <p><strong>Example #3 <span class="function"><strong>Yaf_Route_Regex()</strong></span>example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">/**<br /> * Add a regex route to Yaf_Router route stack by calling addconfig<br /> */<br /> </span><span style="color: #0000BB">$config </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">"name" </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">"type" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"regex"</span><span style="color: #007700">, </span><span style="color: #FF8000">//Yaf_Route_Regex route<br /> </span><span style="color: #DD0000">"match" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"#(.*)#"</span><span style="color: #007700">, </span><span style="color: #FF8000">//match arbitrary request uri<br /> </span><span style="color: #DD0000">"route" </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'controller' </span><span style="color: #007700">=> </span><span style="color: #DD0000">"product"</span><span style="color: #007700">, </span><span style="color: #FF8000">//route to product controller,<br /> </span><span style="color: #DD0000">'action' </span><span style="color: #007700">=> </span><span style="color: #DD0000">"dummy"</span><span style="color: #007700">, </span><span style="color: #FF8000">//route to dummy action<br /> </span><span style="color: #007700">),<br /> </span><span style="color: #DD0000">"map" </span><span style="color: #007700">=> array(<br /> </span><span style="color: #0000BB">1 </span><span style="color: #007700">=> </span><span style="color: #DD0000">"uri"</span><span style="color: #007700">, </span><span style="color: #FF8000">// now you can call $request->getParam("uri")<br /> </span><span style="color: #007700">),<br /> ),<br /> );<br /> </span><span style="color: #0000BB">Yaf_Dispatcher</span><span style="color: #007700">::</span><span style="color: #0000BB">getInstance</span><span style="color: #007700">()-></span><span style="color: #0000BB">getRouter</span><span style="color: #007700">()-></span><span style="color: #0000BB">addConfig</span><span style="color: #007700">(<br /> new </span><span style="color: #0000BB">Yaf_Config_Simple</span><span style="color: #007700">(</span><span style="color: #0000BB">$config</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-yaf-route-regex.construct-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="yaf-router.addroute.html" class="methodname" rel="rdfs-seeAlso">Yaf_Router::addRoute()</a> - Add new Route into Router</span></li> <li class="member"> <span class="methodname"><a href="yaf-router.addconfig.html" class="methodname" rel="rdfs-seeAlso">Yaf_Router::addConfig()</a> - Add config-defined routes into Router</span></li> <li class="member"><a href="class.yaf-route-static.html" class="classname">Yaf_Route_Static</a></li> <li class="member"><a href="class.yaf-route-supervar.html" class="classname">Yaf_Route_Supervar</a></li> <li class="member"><a href="class.yaf-route-simple.html" class="classname">Yaf_Route_Simple</a></li> <li class="member"><a href="class.yaf-route-rewrite.html" class="classname">Yaf_Route_Rewrite</a></li> <li class="member"><a href="class.yaf-route-map.html" class="classname">Yaf_Route_Map</a></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="class.yaf-route-regex.html">Yaf_Route_Regex</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-route-regex.route.html">Yaf_Route_Regex::route</a></div> <div class="up"><a href="class.yaf-route-regex.html">Yaf_Route_Regex</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>