class Yaf_View_Simple implements Yaf_View_Interface (View source)

Yaf_View_Simple is the built-in template engine in Yaf, it is a simple but fast template engine, and only support PHP script template.

Properties

protected string $_tpl_dir
protected array $_tpl_vars
protected array $_options

Methods

__construct(string $template_dir, array|null $options = null)

No description

__isset(string $name)

No description

assign(string|array $name, mixed $value = null)

assign variable to view engine

string|bool
render(string $tpl, array $tpl_vars = null)

No description

bool
display(string $tpl, array $tpl_vars = null)

Render a template and display the result instantly.

assignRef(string $name, mixed $value)

unlike Yaf_View_Simple::assign(), this method assign a ref value to engine.

clear(string $name = null)

clear assigned variable

bool
setScriptPath(string $template_dir)

Set the templates base directory, this is usually called by Yaf_Dispatcher

string
getScriptPath()

No description

mixed
__get(string $name = null)

Retrieve assigned variable


Note:

$name parameter can be empty since 2.1.11

__set(string $name, mixed $value = null)

This is a alternative and easier way to Yaf_View_Simple::assign().

void|false
eval(string $tpl_str, array $vars = null)

Render a string template and return the result.

mixed
get(string $name = '')

No description

Details

final __construct(string $template_dir, array|null $options = null)

No description

Parameters

string $template_dir

The base directory of the templates, by default, it is APPLICATION . "/views" for Yaf.

array|null $options

Options for the engine, as of Yaf 2.1.13, you can use short tag "" in your template(regardless of "short_open_tag"), so comes a option named "short_tag", you can switch this off to prevent use short_tag in template.

Exceptions

Yaf_Exception_TypeError

__isset(string $name)

No description

Parameters

string $name

Yaf_View_Interface|bool assign(string|array $name, mixed $value = null)

assign variable to view engine

Parameters

string|array $name
mixed $value

Return Value

Yaf_View_Interface|bool

string|bool render(string $tpl, array $tpl_vars = null)

No description

Parameters

string $tpl
array $tpl_vars

Return Value

string|bool

Exceptions

Yaf_Exception_LoadFailed_View

bool display(string $tpl, array $tpl_vars = null)

Render a template and display the result instantly.

Parameters

string $tpl
array $tpl_vars

Return Value

bool

Exceptions

Yaf_Exception_LoadFailed_View

Yaf_View_Simple assignRef(string $name, mixed $value)

unlike Yaf_View_Simple::assign(), this method assign a ref value to engine.

Parameters

string $name

A string name which will be used to access the value in the template.

mixed $value

mixed value

Return Value

Yaf_View_Simple

Yaf_View_Simple clear(string $name = null)

clear assigned variable

Parameters

string $name

assigned variable name.
if empty, will clear all assigned variables.

Return Value

Yaf_View_Simple

bool setScriptPath(string $template_dir)

Set the templates base directory, this is usually called by Yaf_Dispatcher

Parameters

string $template_dir

An absolute path to the template directory, by default, Yaf_Dispatcher use application.directory . "/views" as this parameter.

Return Value

bool

string getScriptPath()

No description

Return Value

string

mixed __get(string $name = null)

Retrieve assigned variable


Note:

$name parameter can be empty since 2.1.11

Parameters

string $name

the assigned variable name


if this is empty, all assigned variables will be returned

Return Value

mixed

__set(string $name, mixed $value = null)

This is a alternative and easier way to Yaf_View_Simple::assign().

Parameters

string $name

A string value name.

mixed $value

mixed value

void|false eval(string $tpl_str, array $vars = null)

Render a string template and return the result.

Parameters

string $tpl_str

string template

array $vars

Return Value

void|false

return FALSE on failure

mixed get(string $name = '')

No description

Parameters

string $name

Return Value

mixed