<!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>Get the effective route name</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="yaf-router.construct.html">Yaf_Router::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-router.getroute.html">Yaf_Router::getRoute</a></div> <div class="up"><a href="class.yaf-router.html">Yaf_Router</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="yaf-router.getcurrentroute" class="refentry"> <div class="refnamediv"> <h1 class="refname">Yaf_Router::getCurrentRoute</h1> <p class="verinfo">(Yaf >=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Router::getCurrentRoute</span> — <span class="dc-title">Get the effective route name</span></p> </div> <div class="refsect1 description" id="refsect1-yaf-router.getcurrentroute-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><strong>Yaf_Router::getCurrentRoute</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> Get the name of the route which is effective in the route process. <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> You should call this method after the route process finished, since before that, this method will always return <strong><code>NULL</code></strong>. </p> </p></blockquote> </p> </div> <div class="refsect1 parameters" id="refsect1-yaf-router.getcurrentroute-parameters"> <h3 class="title">Parameters</h3> <p class="para">This function has no parameters.</p> </div> <div class="refsect1 returnvalues" id="refsect1-yaf-router.getcurrentroute-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> String, the name of the effective route. </p> </div> <div class="refsect1 examples" id="refsect1-yaf-router.getcurrentroute-examples"> <h3 class="title">Examples</h3> <div class="example" id="example-4178"> <p><strong>Example #1 Register some routes in Bootstrap</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Bootstrap </span><span style="color: #007700">extends </span><span style="color: #0000BB">Yaf_Bootstrap_Abstract</span><span style="color: #007700">{<br /> public function </span><span style="color: #0000BB">_initConfig</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$config </span><span style="color: #007700">= </span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">::</span><span style="color: #0000BB">app</span><span style="color: #007700">()-></span><span style="color: #0000BB">getConfig</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">Yaf_Registry</span><span style="color: #007700">::</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">"config"</span><span style="color: #007700">, </span><span style="color: #0000BB">$config</span><span style="color: #007700">);<br /> }<br /><br /> public function </span><span style="color: #0000BB">_initRoute</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Dispatcher $dispatcher</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$router </span><span style="color: #007700">= </span><span style="color: #0000BB">$dispatcher</span><span style="color: #007700">-></span><span style="color: #0000BB">getRouter</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">$rewrite_route </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Route_Rewrite</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">"/product/list/:page"</span><span style="color: #007700">,<br /> array(<br /> </span><span style="color: #DD0000">"controller" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"product"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"action" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"list"</span><span style="color: #007700">,<br /> )<br /> ); <br /><br /> </span><span style="color: #0000BB">$regex_route </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Route_Rewrite</span><span style="color: #007700">(<br /> </span><span style="color: #DD0000">"#^/product/info/(\d+)"</span><span style="color: #007700">,<br /> array(<br /> </span><span style="color: #DD0000">"controller" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"product"</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">"action" </span><span style="color: #007700">=> </span><span style="color: #DD0000">"info"</span><span style="color: #007700">,<br /> )<br /> ); <br /> <br /> </span><span style="color: #0000BB">$router</span><span style="color: #007700">-></span><span style="color: #0000BB">addRoute</span><span style="color: #007700">(</span><span style="color: #DD0000">'rewrite'</span><span style="color: #007700">, </span><span style="color: #0000BB">$rewrite_route</span><span style="color: #007700">)-></span><span style="color: #0000BB">addRoute</span><span style="color: #007700">(</span><span style="color: #DD0000">'regex'</span><span style="color: #007700">, </span><span style="color: #0000BB">$regex_route</span><span style="color: #007700">);<br /> } <br /><br /> </span><span style="color: #FF8000">/**<br /> * register plugin <br /> */<br /> </span><span style="color: #007700">public function </span><span style="color: #0000BB">__initPlugins</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Dispatcher $dispatcher</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$dispatcher</span><span style="color: #007700">-></span><span style="color: #0000BB">registerPlugin</span><span style="color: #007700">(new </span><span style="color: #0000BB">DummyPlugin</span><span style="color: #007700">());<br /> }<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-4179"> <p><strong>Example #2 plugin Dummy.php (under <a href="yaf.appconfig.html#configuration.yaf.directory" class="link">application.directory</a>/plugins)</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">DummyPlugin </span><span style="color: #007700">extends </span><span style="color: #0000BB">Yaf_Plugin_Abstract </span><span style="color: #007700">{<br /><br /> public function </span><span style="color: #0000BB">routerShutdown</span><span style="color: #007700">(</span><span style="color: #0000BB">Yaf_Request_Abstract $request</span><span style="color: #007700">, </span><span style="color: #0000BB">Yaf_Response_Abstract $response</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</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">getCurrentRoute</span><span style="color: #007700">());<br /> }<br /></span><span style="color: #0000BB">?><br /></span>?></span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> /* for http://yourdomain.com/product/list/1 * DummyPlugin will output: */ string(7) "rewrite" /* for http://yourdomain.com/product/info/34 * DummyPlugin will output: */ string(5) "regex" /* for other request URI * DummyPlugin will output: */ string(8) "_default" </pre></div> </div> </div> </div> <div class="refsect1 seealso" id="refsect1-yaf-router.getcurrentroute-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><a href="class.yaf-bootstrap-abstract.html" class="classname">Yaf_Bootstrap_Abstract</a></li> <li class="member"><a href="class.yaf-plugin-abstract.html" class="classname">Yaf_Plugin_Abstract</a></li> <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> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="yaf-router.construct.html">Yaf_Router::__construct</a></div> <div class="next" style="text-align: right; float: right;"><a href="yaf-router.getroute.html">Yaf_Router::getRoute</a></div> <div class="up"><a href="class.yaf-router.html">Yaf_Router</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>