Smartyを使ってみる

Twitter ツイート Hatena Bookmark ブックマーク

↓↓poli_smarty.class.phpの中身↓↓

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php
require_once('libs/Smarty.class.php');//Smarty.classを呼び出す
//派生クラスの作成
class PoliSmarty extends Smarty {

    function PoliSmarty() {

        $this-&amp;gt;Smarty();
        $this-&amp;gt;template_dir =  TEMPLATE_DIR;
        $this-&amp;gt;compile_dir=  COMPILE_DIR;
        $this-&amp;gt;config_dir =    CACHE_DIR;
        $this-&amp;gt;cache_dir =    CACHE_DIR;
        $this-&amp;gt;caching =        CACHING;

    }
}
?>

こんな感じになっています。
ちなみに

TEMPLATE_DIR
COMPILE_DIR
CACHE_DIR
CACHING

定数にしてあります。
setting.incファイルを用意してその中に、それぞれのパスを絶対パスで定数の中に入れておきます。

これで下準備完了。

そして、いざ実行させるためにindex.phpを作ってみました。

↓↓poli_smarty.class.phpの中身↓↓

1
2
3
4
5
6
7
8
9
<?php

    $Smarty = new PoliSmarty();
    print_r($Smarty);
    $Smarty-&amp;gt;assign(&quot;data&quot;,&quot;眠い&quot;);

    $Smarty-&amp;gt;display('index.tpl');

?>

こんな感じに書いてみました。
$Smarty->assignでHTMLに表示したい値を入れます。
assign(“変数名”,”値”);
となっているそうです。詳しいことはマニュアルを。。

で、実行してみると。

Be sure $compile_dir is writable by the web server user

とエラーが出ました。
これはどういうことか?
どうやら、ディレクトリのパーミッションの問題でした。
$compile_dirのディレクトリが770になっていたためだめでした。
771でした。

ほかのディレクトリパーミッションも気になりますが…
どうすればいいのだろ。
調べてみよう。

comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。