Smarty3rcから3.0.6 最新版にアップデートしたら以下のエラーが出たのでその対応策
Fatal error: Call to undefined method Smarty_Internal_Resource_File::getTemplateTimestampTypeName() in /var/www/…
Smarty3rcから3.0.6 最新版にアップデートしたら以下のエラーが出たのでその対応策
Fatal error: Call to undefined method Smarty_Internal_Resource_File::getTemplateTimestampTypeName() in /var/www/…
いつものごとく、サイトを作るときはZend Framework+Smartyで作ってます。
今回携帯サイトを作ることになったのですが
けっこう難しかったのでメモ。
» Read more: モバイルサイトをZend Framework+Smartyで構築中
Zend Frameworkを使ったアプリケーションでSmartyテンプレートを使ったメール送信プログラム
よく使いそうなのでメモメモ。。
EUC-JPで作ったテンプレート出力をSHIFT-JISに変更する方法。
//プラグインの登録 $smarty->plugins_dir = array('plugins',APPLICATION_PATH.'/library/plugins/'); //出力フィルターの設定 $smarty->autoload_filters( array("output"=>array("encode_euctosjis")) );
outputfilter.encode_euctosjis.php
function smarty_outputfilter_encode_euctosjis ($buff, &$smarty) { $buff = mb_convert_encoding($buff, 'SJIS', 'EUC'); return $buff; }
ただし!!
$smarty->append()を使った場合はエンコードされたのを、display()でまたエンコードされてしまいうまくいかない。。
初期状態をemptyにする方法
色々適当に設定してたら発見。
{html_select_date
field_array="postege_day"
time="--"
year_empty="選択"
month_empty="選択"
day_empty="選択"
prefix=""
month_format="%m"
field_order="YMD"
end_year="+1"
field_separator=" / "
}
なぜ–でいけるのか不明。
ソースを解読したほうが早かったのかな・・
今回初めて使った関数なので一応メモ
array get_template_vars ( [string varname])
パラメータが与えられない場合は、 全ての割り当てられた変数の配列を返します。
$content_block が無い場合デフォルトのテンプレートを使う
public function append( $template = null , $path=null , $block='content' ) { if (!$path){ $path = $this->_param[controller]; } if (!$template){ $template = $this->_param[action]; } $content = $this->_smarty->fetch($path.'/'.$template.'.tpl' ,md5(serialize($_GET))); $this->_smarty->append($block.'_block',$content); } public function showPage($base = "base") { if ( !$this->_smarty->get_template_vars('content_block') ){ $this->append(); } $this->_smarty->display($base.'.tpl'); }
前回の
http://smarty.incutio.com/にある 便利そうな Block Functions SplitとSplit_rowプラグインを試した。
それぞれ block.split.php block.split_row.php ファイルを作りプラグインフォルダに放り込む。
さて、普通ならここで使えるのだが、
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in 略/block.split.php on line 104
こんなエラーが。。
調べてみると、どうやら参照渡しのやり方が非推進の方法でやられてるらしい。
http://php.net/manual/ja/ini.core.php
なんとか使えるように修正しようとしたがよくわからず挫折しました^^;
allow_call_time_pass_referenceの設定を1のまま使えるようにした方がいたら教えて下さい><
Smartyの修飾子を使ってBBcodeをHTMLに変換してしまうとってもナイスなプラグイン。
http://smarty.incutio.com/
![]()
こちらのサイトの
Extending Smarty
2.SmartyPlugins にある
Modifiers
3. BBCodePlugin – Converts BBCode style tags to HTML
使い方はとっても簡単
BBcodeで書かれたテキストを
{$hoge|bbcode2html}
と記述するだけおk
私の場合、改行タグも付けたかったので最後をちょっと改造
); $message = nl2br($message); //改行をに $message = preg_replace(array_keys($preg), array_values($preg), $message); return $message; }
他にもとても素晴らしいプラグインが多数紹介されているのでSmarty使いには必見のサイトではないでしょうか。
・・・ところで何故bbcode2htmlなんでしょうね?
getパラメーターをURLに戻すプラグイン。
追加や変更したいパラメーターをそのままプラグイン変数に追加するだけの簡単設計w
例
index.php?mode=top&page=main
{url_params hoge="123" hoge2="456"}
↓
mode=top&page=main&hoge=123&hoge2=456
1 2 3 4 5 6 7 8 9 10 11 12 13 | function smarty_function_url_params($params,&$o_smarty){ $params=array_merge($_GET,$params); foreach($params as $key=>$value){ if (is_array($value)){ foreach($value as $array){ $prm[]=$key.'[]='.$array; } }elseif ($value || $value=="0"){ $prm[]=$key.'='.urlencode($value); } } return @implode('&',$prm); } |