■Mojaviとは
PHP用フレームワークの1つです。詳しくは以下のURLを参照
■ディレクトリ構成
ディレクトリ構成は、以下のようになる。
- 【modules】プログラマの主な作業場となるモジュールディレクトリが入ります。
- 【モジュール名】
- 【actions】入力などのビジネスロジックを書きます。
- 【views】表示に関するロジックを書きます。
- 【モジュール名】
- 【template】コーダーの主な作業場となるHTMLテンプレートが入ります。
■アクション部分
以下のルールで記載する。
アクション名Action.class.php
class Test_IndexAction extends Action{
public function execute(){
return View::SUCCESS;
}
}
※execute()内のreturn View::SUCCESS;はSUCCESSというビュー名を返す
■ビュー部分
以下のように記述する。
アクション名ビュー名View.class.php
class Test_IndexSuccessView extends PHPView{
public function execute(){
$this->setDirectory( MO_WEBAPP_DIR.'/templates/Test' );
$this->setTemplate( 'IndexSuccessView.html' );
$var = 'tester';
$this->setAttribute( 'name', $var );
}
}
※setDirectoryはテンプレートHTMLが入っているディレクトリを設定します。
※MO_WEBAPP_DIRは、【modules】の一つ上のディレクトリとなります。
※setTemplate()はテンプレートHTMLのファイル名を設定します。
■テンプレート部分
ファイル名は、Viewで指定したファイル名にする。
置換のタグは以下のように記載する。
<?= $template['name'] ?>