【PHP】【Zend Framework】ビューを使って Hello World

* Controller で Hello Worldの続きみたいなもの
http://blogs.yahoo.co.jp/dk521123/22733849.html

サンプル

フォルダ構成

「*」は、フォルダの意味で、付いてなければ、ファイルを意味する
 * アプリケーションのルートディレクトリ
 |
 +- * public(公開用ディレクトリ)
 |  +- .htaccess
 |  +- index.php
 |
 +- * application(MVCアプリケーションのフォルダ・ファイルを格納するためのディレクトリ)
      +- * controllers(コントローラ関係のファイルを格納するためのディレクトリ)
         |
         +- IndexController.php
         |
         * views (ビュー関係のファイルを格納するためのディレクトリ)
           + * scripts
              + * index
                 +- index.phtml

【1】.htaccess の作成

.htaccess

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|jpeg|png|css|htm|html)$ index.php

【2】フロントコントローラの作成

index.php

<?php
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('../application/controllers');
ini_set( 'display_errors', true);

【3】コントローラの作成

IndexController.php

<?php
require_once 'Zend/Controller/Action.php';

class IndexController extends Zend_Controller_Action {

	//デフォルトのアクションメソッド
	public function indexAction()
	{
		$this->view->message = 'Hello World from Controller!!';
	}
}

【4】ビューの作成

index.phtml

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>Hello World!!!</p>
<div style="color:red;"><?=$this->message ?></div>
</body>
</html>
</body>