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

Name

registerResource() — リソースプラグインを動的に登録します。

説明

void registerResource(string name,
                      array resource_callbacks);

リソースプラグイン を動的に登録します。パラメータとして、 リソース名および実行する PHP ユーザ定義関数の名前を格納した配列を渡します。 テンプレートを取得するための関数の定義の仕方は、 テンプレートリソース の項を参照してください。

テクニカルノート

リソース名の長さは少なくとも2文字以上である必要があります。 1文字のリソース名は無視され、$smarty->display('c:/path/to/index.tpl'); のようにファイルパスの一部として使用されます。

  • 配列 resource_callabcks には4つの要素が必要です。それぞれ sourcetimestampsecure および trusted がリソースの関数としてそれぞれコールバックされます。

  • 各要素で PHP のコールバックを定義します。次のいずれかを指定できます。

    • 関数名を含む文字列

    • array($object, $method) 形式の配列。 &$object はオブジェクトへの参照で、 $method はメソッド名を含む文字列。

    • array($class, $method) 形式の配列。 $class はクラス名で、 $method はクラスのメソッド名。

Example 13.30. registerResource()


<?php
$smarty->registerResource('db', array(
                                'db_get_template',
                                'db_get_timestamp',
                                'db_get_secure',
                                'db_get_trusted')
                                );
?>

   

Example 13.31. registerResource() でのオブジェクトのメソッドの使用


<?php
$smarty->registerResource('db', array(
                                array($obj,'db_get_template'),
                                array($obj,'db_get_timestamp'),
                                array($obj,'db_get_secure'),
                                array($obj,'db_get_trusted')
                                )
                          );
?>

   

unregisterResource() および テンプレートリソース も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors