[PHP-users 29335] Re: smartyでのreplaceの挙動について

Atsushi Kojo a-kojo @ artsnet.jp
2006年 6月 4日 (日) 13:51:59 JST


申し訳ありません。私の環境は
「PHP 4.3.11」「Smarty 2.6.9」です。

> いまいちどのような処理したいのか見えてこないのですが、

要はPHPから給与締日を判別する数値データが来て
レンダリングの際smartyで数値データを人間のわかる
値に置き換えてやろうとしているのです。

※給与締日データ
1→10日
2→15日
3→20日
4→25日
5→末日
6→翌5日

このようにデータを数値化してDBに入れて
数値で取り出し変換して表示する処理は結構あると思いますが
そもそもsmartyのreplaceでの処理は一般的ではないのでしょうか?

> 5の置換が二つ設定されているのがいまいちわからないのですが、
> 6の間違えなのかな?

タイプミスです。ちなみにご指摘があった部分の
コンパイルされたファイルを見てみるとこんな感じです。

$this->_run_mod_handler('replace', true, $_tmp, '1', "10日") :
smarty_modifier_replace($_tmp, '1', "10日")))) ?
$this->_run_mod_handler('replace', true, $_tmp, '2', "15日") :
smarty_modifier_replace($_tmp, '2', "15日")))) ?
$this->_run_mod_handler('replace', true, $_tmp, '3', "20日") :
smarty_modifier_replace($_tmp, '3', "20日")))) ?
$this->_run_mod_handler('replace', true, $_tmp, '4', "25日") :
smarty_modifier_replace($_tmp, '4', "25日")))) ?
$this->_run_mod_handler('replace', true, $_tmp, '5', "末日") :
smarty_modifier_replace($_tmp, '5', "末日")))) ?
$this->_run_mod_handler('replace', true, $_tmp, '6', "翌5日") :
smarty_modifier_replace($_tmp, '6', "翌5日")))) ?
$this->_run_mod_handler('default', true, $_tmp, " ") :
smarty_modifier_default($_tmp, " ")); ?>

多分値が"4"の場合、$_tmpに"4"が入って最初に
$this->_run_mod_handler('replace', true, $_tmp, '4', "25日") :
smarty_modifier_replace($_tmp, '4', "25日")))) ?
に該当して$_tmpの"4"が"25日"に置き換わり、更に
$this->_run_mod_handler('replace', true, $_tmp, '5', "末日") :
smarty_modifier_replace($_tmp, '5', "末日")))) ?
に該当してしまい$_tmpの"25日"が"2末日日"に
置き換わるのだと思います。 




PHP-users メーリングリストの案内