escapeヘルパー
symfonyでのescapeのhelper(helper/EscapingHelper.php)では以下の処理が実行される。
<?php function esc_entities($value) { // Numbers and boolean values get turned into strings which can cause problems // with type comparisons (e.g. === or is_int() etc). return is_string($value) ? htmlentities($value, ENT_QUOTES, sfConfig::get('sf_charset')) : $value; }
このヘルパーを通ってしまうと、ケータイでの表示には少々問題が。
実体参照に変換されてしまう対象の文字が多い。
例えば、以下のような。
- 三点リーダー「…」→ …
- 左矢印「←」→ ←
これが、表示できない(されない)端末がある。
なのでケータイ用には、htmlspecialcharsを使うhelperを用意してあげて、escaping_methodを変えてあげなければいけない。
<?php function _esc($value) { // Numbers and boolean values get turned into strings which can cause problems // with type comparisons (e.g. === or is_int() etc). return is_string($value) ? htmlspecialchars($value, ENT_QUOTES, sfConfig::get('sf_charset')) : $value; } define('ESC_SPECIALCHARS', '_esc');
escaping_methodをESC_ENTITIESからESC_SPECIALCHARSに変更
- apps/(myapp)/config/settings.yml
all: .settings: escaping_strategy: both escaping_method: ESC_SPECIALCHARS standard_helpers: [Partial, Cache, Form] #ここにヘルパーを追加
helperの関数名を短くしてるのは、getData(ESC_RAW)→(他のヘルパー)→エスケープとやるときには直接書くことになって、長いとめんどくさいから。
※追記(2008/07/08 16:40)
ケータイがどうとか関係なく、
≧≦
が
≧≦
ってなっちゃうから、PCでも必須かな。