symfony 1.2で携帯用にSJISで出力する際の注意点
フィルタでSJISに変換して出力している場合、
view.yml で以下のように設定して
default: http_metas: content-type: application/xhtml+xml; charset=Shift_JIS
テンプレート内で以下のようにするとタイトルが空になる。
<?php $sf_response-setTitle('テスト') ?>
sfWebResponse::fixContentType() で charset設定が上書きされてしまい、UTF-8の文字列がSJISでエスケープされるのが原因。
対処法としては以下の2つがありそう。
1. view.ymlではcontent-typeを設定しないでlayout.phpに直接記述する。
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=Shift_JIS" /> <?php include_title() ?> <?php include_metas() ?>
2. 動的にタイトルを変更したい場合はアクション内で行う。
<?php $this->getResponse()-setTitle($var);