Mojavi2の階層構造を打破する(意味なし)
Mojavi2はモジュール構造を特徴とするフレームワークです。
私は通常index.phpにモジュール名やパラメータ名を記述してdispatchしますが、そのおかげで色々なディレクトリにdispatchする為のindex.phpが存在しています。
これらのindex.phpからmojavi2のconfig.phpを読み込むのが結構面倒なので、ちょっと楽できる方法を考えてみました。
方法としては.htaccessを使ったauto_prepend_fileとauto_append_fileの指定です。
php_value auto_prepend_file /path/to/include.php php_value auto_append_file /path/to/dispatch.php
- index.php
// 実行したいActionを指定 $dispatch = array($modName, $actName);
- include.php
require_once(dirname(__FILE__) . '/config.php'); require_once(MOJAVI_FILE);
- dispatch.php
if (isset($dispatch) && is_array($dispatch)) { $controller =& Controller::getInstance(); // その他初期化ルーチン $controller->dispatch($dispatch[0], $dispatch[1]); } // $dispatchが無ければ何もしないで終了する(普通のPHPファイルは避ける)
微妙。。。