symfonyで携帯用にShift_JISで出力する方法

2008-08-19T12:11:14Z | 1分で読めます | 更新日時 2008-08-19T12:11:14Z

@

いろいろと掲載されてはいましたが、結局うまく行かず、悩んでおりましたが、ようやくできました。

  • 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を作成する。
    コードはべたべたなので、綺麗に書いてくださいね。 <?php class MobileFilter extends sfFilter{ public function execute($filterChain = null){ if ($this->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)); } } } }

© 2008 - 2025 橋本たけしの日々を徒然に

🌱 Powered by Hugo with theme Dream.

about me

皆様はじめまして。
今、プログラミング教育が普通に行われていて、普通にPythonとかAIといった言葉が交わされることは喜ばしいことだなぁと感じています。

プログラミングを実際にすることで、もっとこうしたい!と欲が出てきて、いろいろと考えたり、もっと便利にしたい!と思って、世の中のUI/UX/DXのことを理解できたりします。

深さをとことん追求する中で、幅が出て一人ひとりの味が出てくる。
AIに負けない部分は、実はとっても人間らしさだったりします。
本当に必要なことを考えていけたら良いなぁと思っております。