推奨ディレクトリ構成

Zend FrameworkをMVCモデルで使用するときの推奨されるディレクトリ構成です。

CLIツールでコマンドラインからスケルトンを作成することもできます。
[参考記事] CLIツールで雛形作成

application
│├ configs 全体の設定のディレクトリ
││└ application.ini
│├ controllers
││└ helpers
│├ forms
│├ layouts
││├ filters
││├ helpers
││└ scripts
│├ models モデル
│├ modules
│├ services
│├ views ビュー
││├ filters
││├ helpers
││└ scripts
│└ Bootstrap.php
├ data データ階層(これ以下のディレクトリはパーミッションを書き込み可にする)
│├ cache
│├ indexes
│├ locales
│├ logs
│├ sessions
│└ uploadsdocs ドキュメント類
├ librarypublic 公開層(ドキュメントルート)
│├ css スタイルシート
│├ images 画像
│├ js JavaScript
│├ .htaccess
│└ index.php
├ scripts
│├ jobs
│└ buildtemptests ライブラリテスト用(PEAR::PHPUnit2が必要)

MVCモデルの基本構成は
controllers
models
views
となります。

構成をzipファイルにまとめたもの

クイックスタート(ここから簡単なコードサンプルをダウンロードできます)

CLIツールによるディレクトリ構成

[参考記事] CLIツールで雛形作成

┬ .zfproject.xml
├ application
│├ Bootstrap.php
│├ configs
││└ application.ini
│├ controllers
││├ IndexController.php
││├ ErrorController.php
││└ [コントローラ名(先頭1文字は大文字)]Controller.php
│├ models
│├ modules
││└ [モジュール名]
││ ├ controllers
││ ├ models
││ └ views
││  ├ filters
││  ├ helpers
││  └ scripts
│└ views
│ ├ helpers
│ └ scripts
│  ├ [コントローラ名]
│  │├ index.phtml
│  │└ [アクション名].phtml
│  ├ error
│  │└ error.phtml
│  └ index
│   ├ index.phtml
│   └ [アクション名].phtml
├ library
├ public
│├ .htaccess
│└ index.php
└ tests
 ├ application
 │├ bootstrap.php
 │└ controllers
 │ └ [コントローラ名(先頭1文字は大文字)]ControllerTest.php
 ├ library
 │└ bootstrap.php
 └ phpunit.xml

ちなみにController.phpは次のようになる。

<?php

class [コントローラ名(先頭1文字は大文字)]Controller extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function [アクション名]Action()
    {
        // action body
    }


}

関連記事

スポンサーリンク

SUBSTRING関数 文字列を部分的に抽出する

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る