いつものごとく、サイトを作るときはZend Framework+Smartyで作ってます。
今回携帯サイトを作ることになったのですが
けっこう難しかったのでメモ。
» Read more: モバイルサイトをZend Framework+Smartyで構築中
Archive for the ‘Smarty’ category
モバイルサイトをZend Framework+Smartyで構築中
12月 4th, 2009Zend_Mail+Smarty でメール送信
6月 9th, 2008Zend Frameworkを使ったアプリケーションでSmartyテンプレートを使ったメール送信プログラム
よく使いそうなのでメモメモ。。
Smarty 出力フィルター
1月 17th, 2008EUC-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()でまたエンコードされてしまいうまくいかない。。
smarty関数html_select_date
12月 12th, 2007初期状態を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=" / "
}
なぜ–でいけるのか不明。
ソースを解読したほうが早かったのかな・・
Smarty get_template_vars
10月 1st, 2007今回初めて使った関数なので一応メモ
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'); }
Smarty Splitプラグイン
9月 6th, 2007前回の
http://smarty.incutio.com/にある 便利そうな Block Functions SplitとSplit_rowプラグインを試した。
- split – Loop structure similar to foreach that breaks an array into groups as evenly as possible then iterates over those groups. Intended to allow multi column layouts with a minimum of markup in the template code.
- split_row – A variant of split that returns the chunks as rows instead of as columns
それぞれ 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修飾子
9月 5th, 2007Smartyの修飾子を使って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パラメーターを自動作成するsmartyプラグイン
9月 4th, 2007getパラメーターを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); } |
smarty html_radios のlabel_idsパラメータ
8月 29th, 2007smarty本には省略されているがhtml_radiosにlabel_idsパラメータがある。
デフォルトではfalseだけどtrueにしてあげるとlabel idが付加されるのでほぼ標準でつけてもいいと思う。
{html_radios name="radio1" options=$data selected=$select label_ids=true separator="<br />"}
2010/02 追記:
・・・気がつくと本文が抜けている。。
もっと長く書いてあったよな・・・。
どこに消えちゃったんだろう^^;