罪と罰++二律背反

[[PHP]]

-http://smarty.php.net/

*Smarty-2.6.3 セットアップ [#l5b68638]
-付属のファイルをPHPで設定したインクルードパス(include_path)にコピーする
--Smarty.class.php
--Smarty_Compiler.class.php
--Config_File.class.php
--coreディレクトリ
--pluginsディレクトリ
*ディレクトリの構成 [#q390e8a9]
./proj(PHPスクリプト)
-templates(テンプレート)
-cache(キャッシュ)
-templates_c(コンパイルずみテンプレート)
-configs(設定ファイルなど)
*Smartyを使ってみる [#lac793a1]
**テンプレート ./templates/test.tpl [#vcb22f31]
 <html>
 <head>
 <title>{$title}</title>
 </head>
 <body>
 本文:{$honbun} 
 </body>
 </html>
**スクリプト ./test.php [#u3d1327b]
 require 'Smarty.class.php';
 $tpl = new Smarty;
 
 $title = "てすと";
 $tpl->assign("title",$title);
 $tpl->display("test.tpl");
*メソッド [#h47d823f]
|method|説明|
|assign()|テンプレートのタグに値をセット|
|append()|テンプレート変数に値を追加|
|clear_assign()|代入した変数の値をクリア|
|clear_all_assign()||
|register_function()|PHP関数をテンプレート関数として登録|
|clear_cache()|キャッシュをクリア|
|clear_all_cache()||
|unregister_function()|関数登録を解除|
|is_cached()|有効なキャッシュがあればtrue|
|get_template_vars()|現在の変数の一覧|
|display()|テンプレートの内容を出力|
|fetch()|テンプレートの内容を文字列として取得|

*リファレンス [#o81408f8]
-[[PHP/Smarty/修飾子]]

**参照 [#g11c1076]
-和訳マニュアル[[{*smarty*}:http://sunset.freespace.jp/smarty/]]
-[[テンプレートにSJISを使う:http://ns1.php.gr.jp/pipermail/php-users/2003-February/013592.html]]
 function filter_pre($buff, &$tpl){
 	return mb_convert_encoding($buff,"EUC-JP","SJIS");
 }
 function filter_post($buff, &$tpl){
 	return mb_convert_encoding($buff,"SJIS","EUC-JP");
 }
 
 require 'Smarty.class.php';
 $tpl = new Smarty;
 
 $tpl->register_prefilter('filter_pre');
 $tpl->register_postfilter('filter_post');


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS