\CodeLapseSmarty

Smartyラッパークラス

HTMLの自動エスケープや、グローバル変数の機能が追加されたSmartyのラッパークラスです。

読み込みサンプル

<?php
//-- app/b.php

define('APPPATH', dirname(__FILE__));
Config::load(APPPATH . '/config/smarty.php', 'smarty');

// もしくは
// Config::addLoadPath(APPPATH . '/config/');
<?php
//-- app/config/smarty.php

return array(
    // string: テンプレートが保存されているディレクトリ
    'template_dir' => APPPATH . '/templates/',

    // string: コンパイル済みテンプレートを保存するディレクトリ
    'compile_dir' => APPPATH . '/tmp/smarty/compiled/,

    // string: 設定ファイルが保存されているディレクトリ
    'config_dir' => null,

    // string: キャッシュファイルを保存するディレクトリ
    'cache_dir' => APPPATH . '/tmp/smarty/cache/,

    // boolean: キャッシュの有効 / 無効
    'caching' => true,
);
<?php
//-- index.php

$smarty = Smarty::instance();
// *do_something*

Summary

Methods
Properties
Constants
escapeHelper()
instance()
setInGlobal()
setRawInGlobal()
getInGlobal()
clearInGlobal()
clearAllInGlobal()
__construct()
set()
setRaw()
get()
clear()
clearAllAssign()
fetch()
display()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$_globalAssignStore
$_assign
$_smarty
N/A

Properties

$_globalAssignStore

$_globalAssignStore : array

Type

array — グローバル空間に設定された変数名と値を保持します。

$_assign

$_assign : array

Type

array — smartyに割り当てられた値

$_smarty

$_smarty : \CodeLapse\Smarty

Type

\CodeLapse\Smarty — smartyインスタンス

Methods

escapeHelper()

escapeHelper(string|mixed $str) : mixed

与えられた文字列を安全なHTML文字列に変換します。

Parameters

string|mixed $str

エスケープする文字列。

                   文字列でない場合はエスケープ処理は行われず、無視されます。

Returns

mixed —

安全なHTML文字列、もしくは与えられたオブジェクト

instance()

instance(string $name, array $config) : \CodeLapse\Smarty

Smartyのインスタンスを取得します。

Parameters

string $name

(optional) 取得するインスタンスの名前。

                  指定されない場合、'null'を使用します。
array $config

Smartyをインスタンス化するときの設定

Returns

\CodeLapse\Smarty

setInGlobal()

setInGlobal(string|array $name, mixed $value, boolean $escape)

Smartyインスタンス間で共通の変数を設定します。

Parameters

string|array $name

変数名、もしくは、変数名 => 値の連想配列

mixed $value

(optional) 設定する値

boolean $escape

(optional) エスケープを行うかを指定します。デフォルトはtrueです。

setRawInGlobal()

setRawInGlobal(string|array $name,  $value)

Smartyインスタンスで共通の変数を設定します。

setInGlobalと違い、設定する値はエスケープされません。

Parameters

string|array $name

変数名、もしくは、変数名 => 値の連想配列

$value

getInGlobal()

getInGlobal(string $name, string $default)

Smartyインスタンス間で共通の変数を取得します。

Parameters

string $name

変数名

string $default

clearInGlobal()

clearInGlobal(string|array $name)

Smartyインスタンス間で共通の変数を破棄します。

Parameters

string|array $name

破棄する変数名、もしくは破棄する変数名の配列

clearAllInGlobal()

clearAllInGlobal()

Smartyインスタンスで共通の変数をすべて破棄します。

__construct()

__construct(array $config)

Parameters

array $config

Smartyの設定

set()

set(string|array $key, mixed $value, boolean $filtering) : \CodeLapse\Smarty

Smartyに値を割り当てます。

Parameters

string|array $key

テンプレート内の変数名

mixed $value

割り当てる値 / オブジェクト

boolean $filtering

(optional) 値を自動的エスケープするか。デフォルト値はtrue

Returns

\CodeLapse\Smarty

現在のインスタンス

setRaw()

setRaw(string|array $key, mixed $value) : \CodeLapse\Smarty

Smartyに値を割り当てます。

setメソッドとは違い、割り当てた値はエスケープされません。

Parameters

string|array $key

テンプレート内の変数名

mixed $value

割り当てる値 / オブジェクト

Returns

\CodeLapse\Smarty

現在のインスタンス

get()

get(string|array $key, mixed $default) : mixed

Smartyへ割り当てた値を参照します。

変数の参照は以下の順序で行われ、値が見つかった時点でその値が返されます。

  1. インスタンスに割り当てられた値
  2. Smarty共通変数
  3. 渡されたデフォルト値

Parameters

string|array $key

取得する変数名、もしくは取得する変数名の配列

mixed $default

値が設定されていなかった時の初期値

Returns

mixed —

取得した値か、変数名 => 値 の連想配列

clear()

clear(string|array $key) : \CodeLapse\Smarty

Smartyへ割り当てた値を破棄します。

Parameters

string|array $key

破棄する変数名、もしくは、破棄する変数名の配列

Returns

\CodeLapse\Smarty

現在のインスタンス

clearAllAssign()

clearAllAssign() : \CodeLapse\Smarty

Smartyへ割り当てた値をすべて破棄します。

Returns

\CodeLapse\Smarty

現在のインスタンス

fetch()

fetch(string $template, string|null $cache_id, string|null $compile_id)

Smartyの実行結果を取得します。

Parameters

string $template

使用するテンプレート

string|null $cache_id

(optional) キャッシュID

string|null $compile_id

(optional) コンパイルファイルID

display()

display(string $template, string|null $cache_id, string|null $compile_id)

Smartyの実行結果を出力(表示)します。

Parameters

string $template

使用するテンプレート

string|null $cache_id

(optional) キャッシュID

string|null $compile_id

(optional) コンパイルファイルID