| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <!-- EN-Revision: 24249 -->
- <sect3 id="zend.controller.router.routes.chain">
- <title>Zend_Controller_Router_Route_Chain(日本語)</title>
- <para>
- <classname>Zend_Controller_Router_Route_Chain</classname> は、
- 複数のルートを一緒にチェーンできるルートです。
- これは、たとえばホスト名とルート、パスとルート、または複数のパスとルートをチェーンできます。
- チェーンは、プログラム的に、または、構成ファイルの範囲内で行なえます。
- </para>
- <note>
- <title>パラメータ優先度</title>
- <para>
- ルートを一緒にチェーンするとき、
- 外側のルートのパラメータは内側のルートのパラメータより高い優先度を持ちます。
- そういうわけで、外側のもので、そして、内側のルートでコントローラを定義するなら、
- 外側のルートのコントローラが選ばれます。
- </para>
- </note>
- <para>
- プログラム的にチェーンするとき、これを達成する2つの方法があります。
- 最初の1つは、 <classname>Zend_Controller_Router_Route_Chain</classname>
- インスタンスを新規作成して、
- そして、一緒にチェーンでつながなければならないルートすべてで
- <methodname>chain()</methodname> メソッドを複数回呼ぶことです。
- 他の方法は、最初のルート(例えばホスト名のルート)を受け取って、
- それに付加されなければならないルートとともに、
- そのルート上で <methodname>chain()</methodname> メソッドを呼ぶことです。
- これはホスト名ルートを修正せずとも、
- <classname>Zend_Controller_Router_Route_Chain</classname> の新規インスタンスを返します。
- そして、両方のルートは一緒につながれます。
- </para>
- <programlisting language="php"><![CDATA[
- //ルートを2つ作成
- $hostnameRoute = new Zend_Controller_Router_Route_Hostname(...);
- $pathRoute = new Zend_Controller_Router_Route(...);
- //最初の方法では、チェーン・ルートを通じてそれらをチェーンします。
- $chainedRoute = new Zend_Controller_Router_Route_Chain();
- $chainedRoute->chain($hostnameRoute)
- ->chain($pathRoute);
- //次の方法では、それらを直接チェーンします。
- $chainedRoute = $hostnameRoute->chain($pathRoute);
- ]]></programlisting>
- <para>
- ルートを一緒にチェーンするとき、それらの分離記号はデフォルトでスラッシュです。
- 異なる分離記号にしたい場合があるかもしれません。
- </para>
- <programlisting language="php"><![CDATA[
- //ルートを2つ作成
- $firstRoute = new Zend_Controller_Router_Route('foo');
- $secondRoute = new Zend_Controller_Router_Route('bar');
- //それらを異なる分離記号で一緒にチェーンします。
- $chainedRoute = $firstRoute->chain($secondRoute, '-');
- //ルートを結合します: "foo-bar"
- echo $chainedRoute->assemble();
- ]]></programlisting>
- <sect4 id="zend.controller.router.routes.chain.config">
- <title>Zend_Configを介したルートのチェーン</title>
- <para>
- 構成ファイルでルートをチェーンするために、それらの構成のための付加パラメータがあります。
- より単純なアプローチは、 <property>chains</property> パラメータを使うことです。
- このものは単にルートの一覧です。そして、それは親ルートでチェーンされます。
- 親ルートも子供ルートも、結果として生じるチェーンされたルートにだけ直接追加され、
- それ以外のルータには追加されません。
- ルータでのチェーンされたルートの名前は、
- デフォルトでダッシュで連結される親ルート名と子供ルート名です。
- <acronym>XML</acronym> での単純な構成は、このように見えます。
- </para>
- <programlisting language="xml"><![CDATA[
- <routes>
- <www type="Zend_Controller_Router_Route_Hostname">
- <route>www.example.com</route>
- <chains>
- <language type="Zend_Controller_Router_Route">
- <route>:language</route>
- <reqs language="[a-z]{2}">
- <chains>
- <index type="Zend_Controller_Router_Route_Static">
- <route></route>
- <defaults module="default" controller="index"
- action="index" />
- </index>
- <imprint type="Zend_Controller_Router_Route_Static">
- <route>imprint</route>
- <defaults module="default" controller="index"
- action="index" />
- </imprint>
- </chains>
- </language>
- </chains>
- </www>
- <users type="Zend_Controller_Router_Route_Hostname">
- <route>users.example.com</route>
- <chains>
- <profile type="Zend_Controller_Router_Route">
- <route>:username</route>
- <defaults module="users" controller="profile" action="index" />
- </profile>
- </chains>
- </users>
- <misc type="Zend_Controller_Router_Route_Static">
- <route>misc</route>
- </misc>
- </routes>
- ]]></programlisting>
- <para>
- これは結果として、ホスト名及びルート <command>misc</command> に基づいてマッチするだけで、
- どんなホスト名ともマッチする3つのルート、
- <command>www-language-index</command> 、 <command>www-language-imprint</command> 及び
- <command>users-language-profile</command> になります。
- </para>
- <para>
- チェーンされたルートを作成する別な方法は、
- <property>chain</property> パラメータを介することです。
- それはチェーン・ルート型とともにのみ直接使うことができ、
- さらに root レベルでのみ動作します。
- </para>
- <programlisting language="xml"><![CDATA[
- <routes>
- <www type="Zend_Controller_Router_Route_Chain">
- <route>www.example.com</route>
- </www>
- <language type="Zend_Controller_Router_Route">
- <route>:language</route>
- <reqs language="[a-z]{2}">
- </language>
- <index type="Zend_Controller_Router_Route_Static">
- <route></route>
- <defaults module="default" controller="index" action="index" />
- </index>
- <imprint type="Zend_Controller_Router_Route_Static">
- <route>imprint</route>
- <defaults module="default" controller="index" action="index" />
- </imprint>
- <www-index type="Zend_Controller_Router_Route_Chain">
- <chain>www, language, index</chain>
- </www-index>
- <www-imprint type="Zend_Controller_Router_Route_Chain">
- <chain>www, language, imprint</chain>
- </www-imprint>
- </routes>
- ]]></programlisting>
- <para>
- コンマでルートを分離する代わりに、
- 配列として <property>chain</property> パラメータを与えることもできます
- </para>
- <programlisting language="xml"><![CDATA[
- <routes>
- <www-index type="Zend_Controller_Router_Route_Chain">
- <chain>www</chain>
- <chain>language</chain>
- <chain>index</chain>
- </www-index>
- <www-imprint type="Zend_Controller_Router_Route_Chain">
- <chain>www</chain>
- <chain>language</chain>
- <chain>imprint</chain>
- </www-imprint>
- </routes>
- ]]></programlisting>
- <para>
- <classname>Zend_Config</classname> でチェーン・ルートを構成して、
- チェーン名の分離記号をダッシュ以外にしたい場合、
- この分離記号を別途指定する必要があります。
- </para>
- <programlisting language="php"><![CDATA[
- $config = new Zend_Config(array(
- 'chainName' => array(
- 'type' => 'Zend_Controller_Router_Route_Static',
- 'route' => 'foo',
- 'chains' => array(
- 'subRouteName' => array(
- 'type' => 'Zend_Controller_Router_Route_Static',
- 'route' => 'bar',
- 'defaults' => array(
- 'module' => 'module',
- 'controller' => 'controller',
- 'action' => 'action'
- )
- )
- )
- )
- ));
- //構成追加前にセパレータを設定
- $router->setChainNameSeparator('_separator_')
- //構成を追加
- $router->addConfig($config);
- //そしてルート名はこうなります: chainName_separator_subRouteName
- echo $this->_router->assemble(array(), 'chainName_separator_subRouteName');
- //検証: /foo/bar をエコーします。
- ]]></programlisting>
- </sect4>
- </sect3>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|