Smartyを使ってみる
Smartyも無事入ったので、使ってみようと思い派生クラスというものっぽいのを作ってみました。
↓↓poli_smarty.class.phpの中身↓↓
<?php
require_once('libs/Smarty.class.php');//Smarty.classを呼び出す
//派生クラスの作成
class PoliSmarty extends Smarty {
function PoliSmarty() {
$this-&gt;Smarty();
$this-&gt;template_dir = TEMPLATE_DIR;
$this-&gt;compile_dir= COMPILE_DIR;
$this-&gt;config_dir = CACHE_DIR;
$this-&gt;cache_dir = CACHE_DIR;
$this-&gt;caching = CACHING;
}
}
?>
こんな感じになっています。
ちなみに
TEMPLATE_DIR
COMPILE_DIR
CACHE_DIR
CACHING
定数にしてあります。
setting.incファイルを用意してその中に、それぞれのパスを絶対パスで定数の中に入れておきます。
これで下準備完了。
そして、いざ実行させるためにindex.phpを作ってみました。
↓↓poli_smarty.class.phpの中身↓↓
<?php
$Smarty = new PoliSmarty();
print_r($Smarty);
$Smarty-&gt;assign("data","眠い");
$Smarty-&gt;display('index.tpl');
?>
こんな感じに書いてみました。
$Smarty->assignでHTMLに表示したい値を入れます。
assign(“変数名”,”値”);
となっているそうです。詳しいことはマニュアルを。。
で、実行してみると。
Be sure $compile_dir is writable by the web server user
とエラーが出ました。
これはどういうことか?
どうやら、ディレクトリのパーミッションの問題でした。
$compile_dirのディレクトリが770になっていたためだめでした。
771でした。
ほかのディレクトリパーミッションも気になりますが…
どうすればいいのだろ。
調べてみよう。