いろいろと掲載されてはいましたが、結局うまく行かず、悩んでおりましたが、ようやくできました。
- apps/(appname)/config/view.ymlを以下のようにcontent-typeを変更
default: http_metas: content-type: text/html; charset=Shift_JIS
- apps/(appname)/config/filters.ymlを以下のように変更
rendering: ~ web_debug: ~ security: ~ MobileFilter: class: MobileFilter cache: ~ common: ~ flash: ~ execution: ~
- 最後に、lib/filters/MobileFilter.phpを作成する。
コードはべたべたなので、綺麗に書いてくださいね。isFirstCall()){ //error $er=error_reporting(); if ($er > E_STRICT){ error_reporting($er - E_STRICT ); } require_once ('Net/UserAgent/Mobile.php'); $userAgent=Net_UserAgent_Mobile::singleton(); $this->getContext()->getRequest()->setAttribute('userAgent', $userAgent); //出力文字コードの制御 // sfConfig::set('sf_charset',"shift_jis"); sfConfig::set('sf_charset',"UTF-8"); $this->encodingParams('SJIS-win','UTF-8'); mb_internal_encoding('UTF-8'); //mb_http_output('SJIS-win'); // ob_start('mb_output_handler'); ob_start( array($this,'m_output_handler')); } if ($filterChain) $filterChain->execute(); } function m_output_handler($buffer){ sfConfig::set('sf_charset',"shift_jis"); error_log($buffer,3,"/var/www/morenavi/log/mobile.log"); return mb_convert_encoding($buffer,'SJIS-win','UTF-8'); //return $buffer; } protected function encodingParams($from,$to){ if ($to !='' && $from !='' && $from != $to ){ $params=$this->getContext()->getRequest()->getParameterHolder()->getNames(); foreach ($params as $param){ $in=$this->getContext()->getRequest()->getParameter($param); $this->getContext()->getRequest()->setParameter($param, mb_convert_encoding($in,$to,$from)); } } } }
コメント
素晴らしい情報ありがとうございます。非常に助かりました。