Php/Smarty/基本メモ
ダウンロード
http://smarty.php.net/download.php
インストール
解凍してウェブサーバ上にコピーするだけ
接続方法
以下のようにして接続します。
----index.php--------------------------------------------------- <?php require '../Smarty-2.6.18/libs/Smarty.class.php'; $smarty = new Smarty; ?> ----------------------------------------------------------------
helloWorldを表示
用意するファイルとディレクトリ
index.php MySmarty.class.php templates [ディレクトリ] └ - index.tpl templates_c [ディレクトリ]
----index.php---------------------------------------------------
<?php
require 'MySmarty.class.php';
$smarty = new MySmarty;
$smarty->assign("word","helloWorld");
$smarty->assign("word2","helloWorld2");
$smarty->display('index.tpl');
?>
----------------------------------------------------------------
----MySmarty.class.php------------------------------------------
<?php
define("ROOT_DIR","../Smarty-2.6.18");
include_once(ROOT_DIR."/libs/Smarty.class.php");
class MySmarty extends Smarty{
function MySmarty(){
$this->debugging = true;
//$this->debugging = false;
$this->template_dir ="./templates";
$this->compile_dir ="./templates_c";
$this->Smarty();
}
}
?>
----------------------------------------------------------------
----templates-index.tpl------------------------------------------
{$word} {$word2}
<hr>
-----------------------------------------------------------------