<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.yaf-route-regex.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'yaf-route-regex.route.php',
    1 => 'Yaf_Route_Regex::route',
    2 => '路由请求',
  ),
  'up' => 
  array (
    0 => 'class.yaf-route-regex.php',
    1 => 'Yaf_Route_Regex',
  ),
  'prev' => 
  array (
    0 => 'yaf-route-regex.construct.php',
    1 => 'Yaf_Route_Regex::__construct',
  ),
  'next' => 
  array (
    0 => 'class.yaf-route-rewrite.php',
    1 => 'Yaf_Route_Rewrite',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/yaf/yaf_route_regex/route.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaf-route-regex.route" class="refentry">
 <div class="refnamediv">
<h1 class="refname">Yaf_Route_Regex::route</h1>
<p class="verinfo">(Yaf &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">Yaf_Route_Regex::route</span> &mdash; <span class="dc-title">路由请求</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-yaf-route-regex.route-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Yaf_Route_Regex::route</strong></span>(<span class="methodparam"><span class="type"><a href="class.yaf-request-abstract.php" class="type Yaf_Request_Abstract">Yaf_Request_Abstract</a></span> <code class="parameter">$request</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">用正则表达式路由请求：将 URI 与传给构造函数的模式进行匹配，路由结果（module、controller 和 action）取自捕获的变量，并按 map 参数进行映射。</p>
 </div>


 <div class="refsect1 parameters" id="refsect1-yaf-route-regex.route-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt><code class="parameter">request</code></dt>
    <dd>
<p class="simpara">要路由的 <span class="classname"><a href="class.yaf-request-abstract.php" class="classname">Yaf_Request_Abstract</a></span> 实例。</p>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-yaf-route-regex.route-returnvalues">
  <h3 class="title">返回值</h3>
<p class="simpara">若 URI 匹配则返回 <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>，否则返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>，路由器将尝试下一个路由。</p>
 </div>


 <div class="refsect1 examples" id="refsect1-yaf-route-regex.route-examples">
  <h3 class="title">示例</h3>
  <div class="example" id="example-1">
   <p><strong>示例 #1 <span class="methodname"><strong>Yaf_Route_Regex::route()</strong></span> 示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #FF8000">/* 假设请求 URI 为 "/product/php-book" */
</span><span style="color: #0000BB">$request </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Request_Http</span><span style="color: #007700">(</span><span style="color: #DD0000">"/product/php-book"</span><span style="color: #007700">);

</span><span style="color: #0000BB">$route </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Route_Regex</span><span style="color: #007700">(
    </span><span style="color: #DD0000">"#^/product/([^/]+)/?$#"</span><span style="color: #007700">, </span><span style="color: #FF8000">// 匹配以 "/product" 开头的 URI
    </span><span style="color: #007700">array(
        </span><span style="color: #DD0000">'controller' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"product"</span><span style="color: #007700">, </span><span style="color: #FF8000">// 路由到 product 控制器
    </span><span style="color: #007700">),
    array(
        </span><span style="color: #0000BB">1 </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"name"</span><span style="color: #007700">, </span><span style="color: #FF8000">// $request-&gt;getParam("name") 的值将是 "php-book"
    </span><span style="color: #007700">)
);

</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$route</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">route</span><span style="color: #007700">(</span><span style="color: #0000BB">$request</span><span style="color: #007700">));

</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getControllerName</span><span style="color: #007700">());
</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$request</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getParam</span><span style="color: #007700">(</span><span style="color: #DD0000">"name"</span><span style="color: #007700">));
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
   </div>

   <div class="example-contents"><p>以上示例的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">bool(true)
string(7) &quot;product&quot;
string(8) &quot;php-book&quot;</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-yaf-route-regex.route-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="methodname"><a href="yaf-route-regex.construct.php" class="methodname" rel="rdfs-seeAlso">Yaf_Route_Regex::__construct()</a> - Yaf_Route_Regex 构造方法</span></li>
   <li><span class="methodname"><strong>Yaf_Route_Regex::match()</strong></span></li>
   <li><span class="methodname"><a href="yaf-route-regex.assemble.php" class="methodname" rel="rdfs-seeAlso">Yaf_Route_Regex::assemble()</a> - 组合 url</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>