2012年1月16日月曜日

smarty 入門

/*************************************************/
/*        仕事でSmartyを使うんでおさらい     */
/************************************************/


/*-----------ダウンロード---------*/
「http://www.smarty.net/download」より「Smarty 2.6.26」をダウンロード

/*-----------インストール----------*/
「Smarty 2.6.26」を展開し「Smarty」とリネイムし、
今回は「Windows」+「Ampps」環境なので「C:\Ampps\Smarty」に配置する。

/*------------php.iniの設定----------*/
//下記を編集
include_path = ".;C:\ampps\php\includes;C:\Ampps\Smarty\lib"

/*------------ディレクトリの配置----------------------*/
/*下記のように配置します。*/
smarty_sample-
              |-test_app_1
                    |-templates     //テンプレートファイル設置
                    |-templates_c   //コンパイルしたテンプレート設置
                    |-configs       //コンフィグファイル設置
                    |-cache         //キャッシュ
                   
                   
                   
                   
/*--------------テンプレートの作成---------------------------------*/
下記のhtmlソースを「templates_c\index.tpl」に配置、

{*----   テストテンプレート   ----*}

<html>
<head>
<title>Test_1</title>
</head>
<body>

<h1>{$msg}</h1>

</body>
</html>

/*--------------プログラムの作成---------------------------------*/

/*下記を「C:\Ampps\www\smarty_sample\test_app_1」に配置*/
<?php

{*require_once('C:/Ampps/Smarty/libs/Smarty.class.php');*}
require_once('marty.class.php');

$smarty = new Smarty();

$smarty->template_dir = 'C:\Ampps\smarty_sample\test_app_1/templates/';
$smarty->compile_dir  = 'C:\Ampps\smarty_sample\test_app_1/templates_c/';
$smarty->config_dir   = 'C:\Ampps\smarty_sample\test_app_1/configs/';
$smarty->cache_dir    = 'C:\Ampps\smarty_sample\test_app_1/cache/';

$smarty->assign('msg','Hello World!');
$smarty->display('index.tpl');

?>

0 件のコメント:

コメントを投稿