View ディレクトリの場所を変更する方法
Zend Framework でモジューラーディレクトリ構造を使用している場合、View のディレクトリはデフォルトでは各モジュールごとに配置される。
/app `--modules |-- index | |-- controllers | |-- models | `-- views `-- admin |-- controllers |-- models `-- views
モジュールの数が少なかったり、テンプレートの更新がそれほど激しくないのであれば、デフォルトでも良いと思う。
保守とかやっていると、テンプレートの更新が頻繁にあったりする。
バナー張り替えたり、定期コンテンツを変更したりとか。
全てに CMS が入っているのなら、静的ファイルを更新するだけで良いかもしれないがそうでない場合もある。
そうなるとテンプレートはテンプレートだけでまとまって欲しいと思う事がある。
こんな感じ。
/app |-- modules | |-- index | | |-- controllers | | `-- models | `-- admin | |-- controllers | `-- models |-- layouts `-- views `-- scripts |-- index `-- admin
ViewRenderer を使用する場合、ブートストラップとかに以下の様に書く。
<?php $view = new Zend_View(); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(); $viewRenderer->setView($view)->setViewSuffix('.html') ->setViewBasePathSpec('/path/to/app/views' . DIRECTORY_SEPARATOR); ->setViewScriptPathSpec(':module/:controller/:action.:suffix'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
ディレクトリ構成すら柔軟に変更できる。素敵。