Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

拡張セットアップ

これは、基本的なインストール の続きです。まず先にこちらから読んで下さい!

Smarty をより柔軟にするセットアップ方法は、 クラスを拡張 してあなたの Smarty の環境を初期化する事です。 ディレクトリパスの設定を同じ変数に何度も割り当てる代わりに、一箇所でそれらを行う事が出来ます。

新しいディレクトリ/php/includes/guestbook/ を作成し、setup.php という新しいファイルを作成しましょう。 この例の環境では /php/includesinclude_path です。 例と同じようにするか、あるいは絶対パスを使用して下さい。

Example 2.10. /php/includes/guestbook/setup.php


<?php

// Smartyライブラリを読み込みます
require('Smarty.class.php');

// setup.phpはアプリケーションに必要なライブラリファイルを
// 読み込むのに適した場所です。それをここで行うことができます。例:
// require('guestbook/guestbook.lib.php');

class Smarty_GuestBook extends Smarty {

   function Smarty_GuestBook()
   {

        // クラスのコンストラクタ。
        // これらは新しいインスタンスで自動的にセットされます。

        $this->Smarty();

        $this->template_dir = '/web/www.example.com/guestbook/templates/';
        $this->compile_dir  = '/web/www.example.com/guestbook/templates_c/';
        $this->config_dir   = '/web/www.example.com/guestbook/configs/';
        $this->cache_dir    = '/web/www.example.com/guestbook/cache/';

        $this->caching = true;
        $this->assign('app_name', 'Guest Book');
   }

}
?>

    

では、index.php ファイルを修正し、 setup.php を使うようにしてみましょう。

Example 2.11. /web/www.example.com/guestbook/htdocs/index.php


<?php

require('guestbook/setup.php');

$smarty = new Smarty_GuestBook();

$smarty->assign('name','Ned');

$smarty->display('index.tpl');
?>

   

このように、アプリケーションのために全てを自動的に初期化する Smarty_GuestBook() クラスを使う事で、Smarty のインスタンスをとても簡単に作成することができました。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors