Ethnaでモバイル向けSJISサイトを作る

事情により3時間ぐらいで垂直立ち上げという状況になりダッシュで開発。

要件は以下の通り
・3キャリア1サイトSJIS対応(SSL対応端末のみ)
・POST値があり、DBに書き込む
・入力データーのvalidateを行う

Ethna-2.3.5のためEUC-JP→SJISの変換が必要。
postFilterで対応
http://ethna.jp/ethna-document-dev_guide-app-filterchain.html
*1

postFilterに以下の処理を。

function postFilter(){
$content = ob_get_contents();
$content = mb_convert_encoding($content, 'sjis-win', 'eucJP-win');
ob_clean();

echo $content;
ob_end_flush();
}

終わり。

preFilterに以下の処理を。
http://blog.mynet.co.jp/hirashima/2008/01/mobile_web_php_ethna_3html.html

function preFilter(){
ob_start();
$_GET = Filter_convert_encoding_sjis2euc($_GET);
$_POST = Filter_convert_encoding_sjis2euc($_POST);

}


function Filter_convert_encoding_sjis2euc($value){
if(is_array($value)){
return array_map('Filter_convert_encoding_sjis2euc', $value);
}
else{
return mb_convert_encoding($value, 'eucjp-win', 'sjis-win');
}

}

これでvalidate()やActionErrorで追加したエラー文言がSJISできちと表示されます。

  • DB周り

メモがてら残しておくと、importFormするときにdefault値があるcolumnなのでActionForm側で値がはいっていないと全部NULLにされてしまうので、

$appobject>importForm(OBJECT_IMPORT_IGNORE_NULL);

このようにしてあげるとdefault CURRENT_TIMESTAMPとか指定あるカラムが空白になりません。

常識といえば常識なんだけどいざい使うときにわすれるからメモって重要だのぉ(´Д`;)

*1:postFilterっていうとPost値に対するfilterのようだよね