sfSmartyPluginでSmartyフィルタを設定する
sfSmartyPluginでSmartyフィルタを設定した時のメモ
sfSmartyPluginは名前の通りsymfonyでテンプレートエンジンSmartyを使うプラグインである
sfSmartyPlugin(http://www.symfony-project.org/plugins/sfSmartyPlugin)
Smartyフィルタ自体の説明はアシアルさんのブログがわかりやすいのでそちらへ
第9回 Smartyの便利な機能を使いこなす(その3:フィルタ編) (http://www.phppro.jp/school/smarty/vol9/2)
lib/sfSmarty.class.phpのgetSmarty()メソッドの最後の方でフィルタを設定する
public function getSmarty() { /* 既に書かれている色々な処理 */ self::$smarty->load_filter('pre', 'hogeFilter1'); self::$smarty->load_filter('post', 'hogeFilter2'); self::$smarty->load_filter('output', 'hogeFilter3'); }
フィルタプログラムはSmarty本体のディレクトリ\libs\pluginsの中に
ワイル名を フィルタ形式.フィルタ名.php
メソッド名を smarty_フィルタ形式_フィルタ名()
として保存する
Smarty本体のディレクトリ\libs\plugins\prefilter.hogeFilter1.php
<?php function smarty_prefilter_hogeFilter1($sorce, $smarty) { /* 何らかのフィルタ処理 */ $sorce = hogehoge($sorce); return $sorce; }
Smarty本体のディレクトリ\libs\plugins\postfilter.hogeFilter2.php
<?php function smarty_postfilter_hogeFilter2($sorce, $smarty) { /* 何らかのフィルタ処理 */ $sorce = hogehoge($sorce); return $sorce; }
Smarty本体のディレクトリ\libs\plugins\outputfilter.hogeFilter3.php
<?php function smarty_outputfilter_hogeFilter3($sorce, $smarty) { /* 何らかのフィルタ処理 */ $sorce = hogehoge($sorce); return $sorce; }
おわり