<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.yaf.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ru',
  ),
  'this' => 
  array (
    0 => 'class.yaf-router.php',
    1 => 'Yaf_Router',
    2 => 'Класс Yaf_Router',
  ),
  'up' => 
  array (
    0 => 'book.yaf.php',
    1 => 'Yaf',
  ),
  'prev' => 
  array (
    0 => 'yaf-route-rewrite.route.php',
    1 => 'Yaf_Route_Rewrite::route',
  ),
  'next' => 
  array (
    0 => 'yaf-router.addconfig.php',
    1 => 'Yaf_Router::addConfig',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ru',
    'path' => 'reference/yaf/yaf-router.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.yaf-router.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.yaf-router" class="reference">

 <h1 class="title">Класс Yaf_Router</h1>
 

 <div class="partintro"><p class="verinfo">(Yaf &gt;=1.0.0)</p>


  <div class="section" id="yaf-router.intro">
   <h2 class="title">Введение</h2>
   <p class="para">
    <span class="classname"><strong class="classname">Yaf_Router</strong></span> - это стандартный каркасный маршрутизатор. Маршрутизация - это
    процесс получения конечной точки URI (той части URI, которая идёт
    после базового URI: смотрите <span class="methodname"><a href="yaf-request-abstract.setbaseuri.php" class="methodname">Yaf_Request_Abstract::setBaseUri()</a></span>)
    и разложение её на параметры, чтобы определить, какой модуль, контроллер
    и действие должны получить запрос. Эти значения модуля,
    контроллера, действия и других параметров упакованы в объект
    <span class="classname"><a href="class.yaf-request-abstract.php" class="classname">Yaf_Request_Abstract</a></span>, который затем обрабатывается
    <span class="classname"><a href="class.yaf-dispatcher.php" class="classname">Yaf_Dispatcher</a></span>. Маршрутизация происходит только один раз: при первоначальном
    получении запроса и до отправки первого контроллера.

    <span class="classname"><strong class="classname">Yaf_Router</strong></span> предназначен для обеспечения функциональности, подобной mod_rewrite,
    с использованием чистых структур PHP. Он основан на маршрутизации Ruby
    on Rails и не требует каких-либо предварительных знаний о перезаписи URL
    веб-сервера. Он предназначен для работы с одним правилом Apache mod_rewrite
    (одним из):
   <div class="example" id="example-1">
    <p><strong>Пример #1 Правило перезаписи для Apache</strong></p>
   <div class="example-contents">
<div class="confcode"><pre class="confcode">RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|html)$ index.php</pre>
</div>
   </div>

   </div>
   или (предпочтительнее):
   <div class="example" id="example-2">
   <p><strong>Пример #2 Правило перезаписи для Apache</strong></p>
   <div class="example-contents">
<div class="confcode"><pre class="confcode">RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]</pre>
</div>
   </div>

  </div>
   При использовании Lighttpd используйте следующее правило перезаписи:
   <div class="example" id="example-3">
    <p><strong>Пример #3 Правило перезаписи для Lighttpd</strong></p>
   <div class="example-contents">
<div class="confcode"><pre class="confcode">url.rewrite-once = (
  &quot;.*\?(.*)$&quot; =&gt; &quot;/index.php?$1&quot;,
  &quot;.*\.(js|ico|gif|jpg|png|css|html)$&quot; =&gt; &quot;$0&quot;,
  &quot;&quot; =&gt; &quot;/index.php&quot;
)</pre>
</div>
   </div>

  </div>
   При использовании Nginx используйте следующее правило перезаписи:
   <div class="example" id="example-4">
    <p><strong>Пример #4 Правило перезаписи для Nginx</strong></p>
   <div class="example-contents">
<div class="confcode"><pre class="confcode">server {
  listen ****;
  server_name  yourdomain.com;
  root   document_root;
  index  index.php index.html;

  if (!-e $request_filename) {
    rewrite ^/(.*)  /index.php/$1 last;
  }
}</pre>
</div>
   </div>

  </div>
   </p>
  </div>


  <div class="section" id="yaf-router.default">
   <h2 class="title">Маршрут по умолчанию</h2>
   <p class="para">
    <span class="classname"><strong class="classname">Yaf_Router</strong></span> поставляется с предварительно настроенным маршрутом по умолчанию
    <span class="classname"><a href="class.yaf-route-static.php" class="classname">Yaf_Route_Static</a></span>, который будет соответствовать URI в форме
    контроллера/действия. Кроме того, имя модуля может быть указано в качестве первого
    элемента пути, что позволяет использовать URI формы модуля/контроллера/действия. Наконец,
    он также будет соответствовать любым дополнительным параметрам, добавляемым к URI по умолчанию
    - controller /action/var1/value1/var2/value2.
    <blockquote class="note"><p><strong class="note">Замечание</strong>: 
     <p class="para">
      Имя модуля должно быть определено в конфигурации с учётом application.module=&quot;Index,Foo,Bar&quot;,
      в этом случае только index, foo и bar могут рассматриваться как имя модуля.
      Если не настроено, есть только один модуль с именем &quot;Index&quot;.
     </p>
    </p></blockquote>
   </p>

   <p class="para">
   Некоторые примеры соответствия таких маршрутов:
   <div class="example" id="example-5">
    <p><strong>Пример #5 Пример использования <span class="classname"><a href="class.yaf-route-static.php" class="classname">Yaf_Route_Static</a></span>(маршрут по умолчанию)</strong></p>
   <div class="example-contents">
<div class="confcode"><pre class="confcode">// Предполагая следующую настройку:
$conf = array(
   &quot;application&quot; =&gt; array(
      &quot;modules&quot; =&gt; &quot;Index,Blog&quot;,
   ),
);

Только контроллер:
http://example/news
    controller == news
Только действие (если определено yaf.action_prefer=1 в php.ini)
    action  == news

Неверный модуль отображается на имя контроллера:
http://example/foo
    controller == foo

Модуль + контроллер:
http://example/blog/archive
    module     == blog
    controller == archive

Модуль + контроллер + действие:
http://example/blog/archive/list
    module     == blog
    controller == archive
    action     == list

Модуль + контроллер + действие + параметры:
http://example/blog/archive/list/sort/alpha/date/desc
    module     == blog
    controller == archive
    action     == list
    sort       == alpha
    date       == desc</pre>
</div>
   </div>

  </div>

  </p>
  </div>

  <div class="section" id="yaf-router.synopsis">
   <h2 class="title">Обзор класса</h2>


   <div class="classsynopsis">
    <span class="ooclass"><strong class="classname"></strong></span>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Yaf_Router</strong>
     </span>
     {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Свойства */</div>
    <div class="fieldsynopsis">
     <span class="modifier">protected</span>
      <var class="varname"><a href="class.yaf-router.php#yaf-router.props.routes">$<var class="varname">_routes</var></a></var>;</div>

    <div class="fieldsynopsis"><span class="modifier">protected</span>
      <var class="varname"><a href="class.yaf-router.php#yaf-router.props.current">$<var class="varname">_current</var></a></var>;</div>



    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Методы */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="yaf-router.construct.php" class="methodname">__construct</a></span>()</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.addconfig.php" class="methodname">addConfig</a></span>(<span class="methodparam"><span class="type"><a href="class.yaf-config-abstract.php" class="type Yaf_Config_Abstract">Yaf_Config_Abstract</a></span> <code class="parameter">$config</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.addroute.php" class="methodname">addRoute</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>, <span class="methodparam"><span class="type">Yaf_Route_Abstract</span> <code class="parameter">$route</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.getcurrentroute.php" class="methodname">getCurrentRoute</a></span>(): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.getroute.php" class="methodname">getRoute</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$name</code></span>): <span class="type"><a href="class.yaf-route-interface.php" class="type Yaf_Route_Interface">Yaf_Route_Interface</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.getroutes.php" class="methodname">getRoutes</a></span>(): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="yaf-router.route.php" class="methodname">route</a></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>

   }</div>


  </div>



  <div class="section" id="yaf-router.props">
   <h2 class="title">Свойства</h2>
   <dl>
    
     <dt id="yaf-router.props.routes"><var class="varname">_routes</var></dt>
     <dd>
      <p class="para">
      стек зарегистрированных маршрутов
      </p>
     </dd>
    
    
     <dt id="yaf-router.props.current"><var class="varname">_current</var></dt>
     <dd>
      <p class="para">
       после фазы маршрутизации указывается название того, какой маршрут
       используется для маршрутизации текущего запроса.

       Вы можете получить его имя с помощью
       <span class="methodname"><a href="yaf-router.getcurrentroute.php" class="methodname">Yaf_Router::getCurrentRoute()</a></span>.
      </p>
     </dd>
    
   </dl>
  </div>



 </div>

 













































<h2>Содержание</h2><ul class="chunklist chunklist_reference"><li><a href="yaf-router.addconfig.php">Yaf_Router::addConfig</a> — Добавляет настроенные маршруты в маршрутизатор</li><li><a href="yaf-router.addroute.php">Yaf_Router::addRoute</a> — Добавляет новый маршрут в маршрутизатор</li><li><a href="yaf-router.construct.php">Yaf_Router::__construct</a> — Конструктор класса Yaf_Router</li><li><a href="yaf-router.getcurrentroute.php">Yaf_Router::getCurrentRoute</a> — Получает имя действующего маршрута</li><li><a href="yaf-router.getroute.php">Yaf_Router::getRoute</a> — Получает маршрут по имени</li><li><a href="yaf-router.getroutes.php">Yaf_Router::getRoutes</a> — Получает зарегистрированные маршруты</li><li><a href="yaf-router.route.php">Yaf_Router::route</a> — Назначение route</li></ul>
</div>
<?php manual_footer($setup); ?>