EthnaでShift_JISなページを作る
Ethna で,一部のページを携帯用の Shift_JIS コードでコンテンツを出力する方法です。
Ethna 全体を Shift_JIS化する方法は
EthnaでShift_JISなサイトを作る (ethna.jp)
を参照すればなんとかなるのですが,一部のページだけを変換するにはこれでは(たぶん)足りません。
まず,アプリケーション構築後に自動生成される「Sample_ViewClass」を継承する「Sample_MobileViewClass」を生成します。
この中で,Smartyを経由して出力されたデータの文字コードを一括して変換します。
require_once('Sample_ViewClass.php');class Sample_MobileViewClass extends Sample_ViewClass
{
function preforward() {
parent::preforward();
ob_start();
}function forward() {
parent::forward();$str = mb_convert_encoding (ob_get_contents(), 'SJIS', 'EUC-JP');
ob_clean();
echo $str;
ob_end_flush();
}
}
以上のクラスを携帯用のページのビュークラスで「Sample_ViewClass」の代わりに親クラスとして継承します。
require_once('Sample_MobileViewClass.php');class Sample_View_M extends Sample_MobileViewClass
{
function preforward() {
parent::preforward();// 通常の処理
}
}