<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'yaf.tutorials.php',
    1 => '例',
    2 => '例',
  ),
  'up' => 
  array (
    0 => 'book.yaf.php',
    1 => 'Yaf',
  ),
  'prev' => 
  array (
    0 => 'yaf.constants.php',
    1 => '定義済み定数',
  ),
  'next' => 
  array (
    0 => 'yaf.appconfig.php',
    1 => 'アプリケーションの設定',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/yaf/tutorials.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="yaf.tutorials" class="chapter">
 <h1 class="title">例</h1>


 <div class="example" id="example-1">
   <p><strong>例1 標準的なアプリケーションのディレクトリ構造</strong></p>
  <div class="example-contents screen">
<div class="cdata"><pre>
- index.php 
- .htaccess 
+ conf
  |- application.ini // アプリケーションの設定
- application/
  - Bootstrap.php   
  + controllers
     - Index.php // デフォルトのコントローラ
  + views    
     |+ index   
        - index.phtml // デフォルトアクション用のビューテンプレート
  + modules 
  - library
  - models  
  - plugins 
</pre></div>
  </div>
 </div>

 <div class="example" id="example-2">
  <p><strong>例2 エントリ</strong></p>
  <div class="example-contents"><p>
   トップディレクトリの index.php が、アプリケーションの唯一の入り口です。
   index.php へのすべてのリクエストをリダイレクトしなければいけません
   (Apache+mod_php なら .htaccess を使えます)。
  </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />define</span><span style="color: #007700">(</span><span style="color: #DD0000">"APPLICATION_PATH"</span><span style="color: #007700">,  </span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">$app  </span><span style="color: #007700">= new </span><span style="color: #0000BB">Yaf_Application</span><span style="color: #007700">(</span><span style="color: #0000BB">APPLICATION_PATH </span><span style="color: #007700">. </span><span style="color: #DD0000">"/conf/application.ini"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$app</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bootstrap</span><span style="color: #007700">() </span><span style="color: #FF8000">// Bootstrap.php で定義した bootstrap メソッドを呼びます<br /> </span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">run</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

 </div>

 <div class="example" id="example-3">
  <p><strong>例3 リライトルール</strong></p>
  <div class="example-contents screen">
<div class="cdata"><pre>
#for apache (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

#for nginx
server {
  listen ****;
  server_name  domain.com;
  root   document_root;
  index  index.php index.html index.htm;

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

#for lighttpd
$HTTP[&quot;host&quot;] =~ &quot;(www.)?domain.com$&quot; {
  url.rewrite = (
     &quot;^/(.+)/?$&quot;  =&gt; &quot;/index.php/$1&quot;,
  )
}
</pre></div>
  </div>
 </div>

 <div class="example" id="example-4">
  <p><strong>例4 アプリケーションの設定</strong></p>
   <div class="example-contents">
<div class="inicode"><pre class="inicode">[yaf]
; APPLICATION_PATH は index.php で定義した定数
application.directory=APPLICATION_PATH &quot;/application/&quot; 

; product セクションは yaf セクションを継承する
[product:yaf]
foo=bar</pre>
</div>
   </div>

 </div>

 <div class="example" id="example-5">
  <p><strong>例5 デフォルトのコントローラ</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">IndexController </span><span style="color: #007700">extends </span><span style="color: #0000BB">Yaf_Controller_Abstract </span><span style="color: #007700">{<br />   </span><span style="color: #FF8000">/* デフォルトアクション */<br />   </span><span style="color: #007700">public function </span><span style="color: #0000BB">indexAction</span><span style="color: #007700">() {<br />       </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">_view</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">word </span><span style="color: #007700">= </span><span style="color: #DD0000">"hello world"</span><span style="color: #007700">;<br />       </span><span style="color: #FF8000">// あるいは<br />       // $this-&gt;getView()-&gt;word = "hello world";<br />   </span><span style="color: #007700">}<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

 </div>

 <div class="example" id="example-6">
  <p><strong>例6 デフォルトのビューテンプレート</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">&lt;html&gt;<br /> &lt;head&gt;<br />   &lt;title&gt;Hello World&lt;/title&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt;<br />   <span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #0000BB">$word</span><span style="color: #007700">;</span><span style="color: #0000BB">?&gt;<br /></span> &lt;/body&gt;<br />&lt;/html&gt;</span></code></div>
   </div>

 </div>

 <div class="example" id="example-7">
  <p><strong>例7 アプリケーションの実行</strong></p>
  <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
  <div class="example-contents screen">
<div class="cdata"><pre>
&lt;html&gt;
 &lt;head&gt;
   &lt;title&gt;Hello World&lt;/title&gt;
 &lt;/head&gt;
 &lt;body&gt;
   hello world
 &lt;/body&gt;
&lt;/html&gt;
</pre></div>
  </div>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    このサンプルは Yaf のコードジェネレータで生成できます。コードジェネレータは
    yaf@github にあります。
   </p>
  </p></blockquote>
 </div>

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