ethna の action・view は共通としテンプレートだけを切り替える。以前の
/blog/remix/2009/09/post_186.html
を改良。
shopA は
APPID/template/ja/shopA/Index.tpl
shopB は
APPID/template/ja/shopB/Index.tpl
さらに、shopXを追加したときにテンプレートが無ければ自動的に標準の
APPID/template/ja/shop/Index.tpl
を使う。
'A','B','X' をデータベースなどから取得してテンプレートを動的に切り替え、'shop' を config値 から取得する。
/blog/remix/2009/09/post_186.html
を改良。
shopA は
APPID/template/ja/shopA/Index.tpl
shopB は
APPID/template/ja/shopB/Index.tpl
さらに、shopXを追加したときにテンプレートが無ければ自動的に標準の
APPID/template/ja/shop/Index.tpl
を使う。
'A','B','X' をデータベースなどから取得してテンプレートを動的に切り替え、'shop' を config値 から取得する。
APPID-ini.php で config値を定義
'SWITCH' => 'store',コントローラー APPID_Controller.php
var $switchBase = ''; var $switchName = ''; function getTemplatedir(){ $cfg = $this->config->get(); if( isset( $cfg['SWITCH'] ) ){ $this->switchBase = $cfg['SWITCH']; } $dir = parent::getTemplatedir(); /// ↓さらに追加する if( 0 > strlen( $this->switchBase . $this->switchName ) ){ /// switchBase 制御するとき $dir .= '/' . $this->switchBase . $this->switchName; } return $dir; } function setSwitchName($switchName){ $this->switchName = $switchName; } function getSwitchName(){ return $this->switchName; } function getSwitchBase(){ return $this->switchBase; }viewの継承元 APPID_ViewClass.php
function forward(){ $controller =& $this->backend->getController(); $dir = $controller->getTemplatedir(); if( ! file_exists( "{$Templatedir}/{$this->forward_path}" ) ){ /// テンプレートファイルがなければデフォルト(基底)にもどす $controller->setSwitchName( '' ); } /// ↑先に切り替える parent::forward(); }あとは、適当なアクションで
$controller =& $this->backend->getController(); $controller->setSwitchName( 'A' );Ethna-2.3.7、Ethna-2.5.0 で確認。
注意:Ethnaではクラスファクトリで1つのレンダラーオブジェクトを使いまわすのでEthna_MailSender などを使った後、このgetSwitchName()してもTemplatedirが更新できないので注意が必要。その3に続く・・・