class HtmlView extends JObject

Base class for a Joomla View

Class holding methods for displaying presentation data.

Properties

JDocument $document The active document object

Methods

__construct( array $config = array())

Constructor

mixed
display( string $tpl = null)

Execute and display a template script.

boolean
assign()

Assigns variables to the view script via differing strategies.

boolean
assignRef( string $key, mixed $val)

Assign variable for the view (by reference).

mixed
escape( mixed $var)

Escapes a value for output in a view script.

mixed
get( string $property, string $default = null)

Method to get data from a registered model or a property of the view

mixed
getModel( string $name = null)

Method to get the model object

string
getLayout()

Get the layout.

string
getLayoutTemplate()

Get the layout template.

string
getName()

Method to get the view name

JModelLegacy
setModel( JModelLegacy $model, boolean $default = false)

Method to add a model to the view. We support a multiple model single view system by which models are referenced by classname. A caveat to the classname referencing is that any classname prepended by \JModel will be referenced by the name without \JModel, eg. \JModelCategory is just Category.

string
setLayout( string $layout)

Sets the layout name to use

string
setLayoutExt( string $value)

Allows a different extension for the layout files to be used

void
setEscape( mixed $spec)

Sets the _escape() callback.

void
addTemplatePath( mixed $path)

Adds to the stack of view script paths in LIFO order.

void
addHelperPath( mixed $path)

Adds to the stack of helper script paths in LIFO order.

string
loadTemplate( string $tpl = null)

Load a template file -- first look in the templates folder for an override

void
loadHelper( string $hlp = null)

Load a helper file

mixed
getForm()

Returns the form object

void
setDocumentTitle( string $title)

Sets the document title according to Global Configuration options

Details

__construct( array $config = array())

Constructor

Parameters

array $config A named configuration array for object construction. name: the name (optional) of the view (defaults to the view class name suffix). charset: the character set to use for display escape: the name (optional) of the function to use for escaping strings basepath: the parent path (optional) of the views directory (defaults to the component folder) templateplath: the path (optional) of the layout directory (defaults to basepath + /views/ + view name helperpath: the path (optional) of the helper files (defaults to base_path + /helpers/) layout: the layout (optional) to use to display the view

mixed display( string $tpl = null)

Execute and display a template script.

Parameters

string $tpl The name of the template file to parse; automatically searches through the template paths.

Return Value

mixed A string if successful, otherwise an Error object.

See also

\JViewLegacy::loadTemplate()

boolean assign()

Assigns variables to the view script via differing strategies.

This method is overloaded; you can assign all the properties of an object, an associative array, or a single value by name.

You are not allowed to set variables that begin with an underscore; these are either private properties for \JView or private variables within the template script itself.

$view = new \Joomla\CMS\View\HtmlView;

// Assign directly $view->var1 = 'something'; $view->var2 = 'else';

// Assign by name and value $view->assign('var1', 'something'); $view->assign('var2', 'else');

// Assign by assoc-array $ary = array('var1' => 'something', 'var2' => 'else'); $view->assign($obj);

// Assign by object $obj = new \stdClass; $obj->var1 = 'something'; $obj->var2 = 'else'; $view->assign($obj);

Return Value

boolean True on success, false on failure.

boolean assignRef( string $key, mixed $val)

Assign variable for the view (by reference).

You are not allowed to set variables that begin with an underscore; these are either private properties for \JView or private variables within the template script itself.

$view = new \JView;

// Assign by name and value $view->assignRef('var1', $ref);

// Assign directly $view->var1 = &$ref;

Parameters

string $key The name for the reference in the view.
mixed $val &$val The referenced variable.

Return Value

boolean True on success, false on failure.

mixed escape( mixed $var)

Escapes a value for output in a view script.

If escaping mechanism is either htmlspecialchars or htmlentities, uses {@link $_encoding} setting.

Parameters

mixed $var The output to escape.

Return Value

mixed The escaped value.

mixed get( string $property, string $default = null)

Method to get data from a registered model or a property of the view

Parameters

string $property The name of the method to call on the model or the property to get
string $default The name of the model to reference or the default value [optional]

Return Value

mixed The return value of the method

mixed getModel( string $name = null)

Method to get the model object

Parameters

string $name The name of the model (optional)

Return Value

mixed \JModelLegacy object

string getLayout()

Get the layout.

Return Value

string The layout name

string getLayoutTemplate()

Get the layout template.

Return Value

string The layout template name

string getName()

Method to get the view name

The model name by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor

Return Value

string The name of the model

Exceptions

Exception

JModelLegacy setModel( JModelLegacy $model, boolean $default = false)

Method to add a model to the view. We support a multiple model single view system by which models are referenced by classname. A caveat to the classname referencing is that any classname prepended by \JModel will be referenced by the name without \JModel, eg. \JModelCategory is just Category.

Parameters

JModelLegacy $model The model to add to the view.
boolean $default Is this the default model?

Return Value

JModelLegacy The added model.

string setLayout( string $layout)

Sets the layout name to use

Parameters

string $layout The layout name or a string in format