Hello, world


インストール


ファイル構成

参考ページと違うファイル構成とする
/opt/lampp/htdocs/
Zend/
    application/
        controllers/
            IndexController.php
            ErrorController.php
        models/
        views/
            scripts/
               index/
                  index.phtml
                  error.phtml
            helpers/
            filters/
    .htaccess
    index.php

起動ファイル(index.php) の作成

すべてのアクセスはこのファイルを通して実行される

<?php
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('application/controllers'); // コントローラへのパス


デフォルトのコントローラ(IndexController.php)の作成


<?php
/** Zend_Controller_Action */
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action
{
   public function indexAction()
   {
   }
}

ビュースクリプト(index.phtml)の作成

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>My first Zend Framework App</title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

エラーコントローラ(ErrorController.php)の作成


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

class ErrorController extends Zend_Controller_Action
{
    public function errorAction()
    {
    }
}

エラースクリプト(Error.phtml)の作成



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>エラー</title>
</head>
<body>
   <h1>エラーが発生しました</h1>
   <p>エラーが発生しました。後ほどもう一度お試しください。</p>
</body>
</html>
最終更新:2008年01月10日 14:09