Pfw_XH
Public Member Functions | Protected Member Functions | List of all members
Pfw\View\View Class Reference

Generation of properly escaped HTML. More...

Public Member Functions

 __construct ($pluginname)
 Initialize the instance. More...
 
 template ($name)
 Assign a view template. More...
 
 data (array $data)
 Assign view data. More...
 
 render ()
 Render the view template. More...
 
 escape ($value)
 Escapes HTML. More...
 

Protected Member Functions

 text ($key)
 Return a properly escaped localized language text. More...
 
 plural ($key, $count)
 Return a properly escaped pluralized localized language text. More...
 

Detailed Description

Generation of properly escaped HTML.

Example:

(new View($pluginname))
    ->template('foo')        // assign a template
    ->data(['bar' => 'baz']) // assign view data
    ->render();              // render the view

Constructor & Destructor Documentation

◆ __construct()

Pfw\View\View::__construct (   $pluginname)

Initialize the instance.

$pluginname is the name of the instantiating plugin, and is used to look up the template and any language texts.

Parameters
string$pluginname

Member Function Documentation

◆ data()

Pfw\View\View::data ( array  $data)

Assign view data.

$data is an associative array, and its elements are available as local variables in the view template. All values, except booleans, are encapsulated as ViewValues to ensure proper HTML escaping which is supposed to happen automagically.

Returns
$this

◆ escape()

Pfw\View\View::escape (   $value)

Escapes HTML.

This method is supposed to be called automagically when needed, but never explicitly.

Parameters
mixed$value

◆ plural()

Pfw\View\View::plural (   $key,
  $count 
)
protected

Return a properly escaped pluralized localized language text.

The $key is suffixed with the appropriate number suffix according to the current language's rules, which works basically the same as gettext's plurals. The suffixed key is then looked up in the active language file of the plugin the view is associated with, and if it is not there it is looked up in Pfw_XH's language file. Additional arguments may be passed to substitute printf-style placeholders in the language text.

Parameters
string$key
int$count
Returns
string

◆ render()

Pfw\View\View::render ( )

Render the view template.

This method includes the assigned template making the view data available as local variables.

Returns
void

◆ template()

Pfw\View\View::template (   $name)

Assign a view template.

The view template is looked up in the views/ folder of the calling plugin with the basename $name.php.

Parameters
string$name
Returns
$this

◆ text()

Pfw\View\View::text (   $key)
protected

Return a properly escaped localized language text.

The $key is looked up in the active language file of the plugin the view is associated with, and if it is not there it is looked up in Pfw_XH's language file. Additional arguments may be passed to substitute printf-style placeholders in the language text.

Parameters
string$key
Returns
string

The documentation for this class was generated from the following file: