サンプル
フォルダ構成
「*」は、フォルダの意味で、付いてなければ、ファイルを意味する
* アプリケーションのルートディレクトリ
|
+- * public(公開用ディレクトリ)
| +- .htaccess
| +- index.php
|
+- * application(MVCアプリケーションのフォルダ・ファイルを格納するためのディレクトリ)
+- * controllers(コントローラ関係のファイルを格納するためのディレクトリ)
|
+- IndexController.php
|
* views (ビュー関係のファイルを格納するためのディレクトリ)
+ * scripts
+ * index
+- index.phtml
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|jpeg|png|css|htm|html)$ index.php
【2】フロントコントローラの作成
<?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>