HtmlView

Extends JObject

Base class for a Joomla View

Class holding methods for displaying presentation data.

since

2.5.5

package

Joomla CMS

Methods

__construct

Constructor

__construct(array config = array()) : mixed
since

3.0

Arguments

config

arrayA 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 base_path: the parent path (optional) of the views directory (defaults to the component folder) template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/) layout: the layout (optional) to use to display the view

Response

mixed

_addPath

Adds to the search path for templates and resources.

_addPath(string type, mixed path) : void
since

3.0

Arguments

type

stringThe type of path to add.

path

mixedThe directory or stream, or an array of either, to search.

_createFileName

Create the filename for a resource

_createFileName(string type, array parts = array()) : string
since

3.0

Arguments

type

stringThe resource type to create the filename for

parts

arrayAn associative array of filename information

Response

stringThe filename

_setPath

Sets an entire array of search paths for templates or resources.

_setPath(string type, mixed path) : void
since

3.0

Arguments

type

stringThe type of path to set, typically 'template'.

path

mixedThe new search path, or an array of search paths. If null or false, resets to the current directory only.

addHelperPath

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

addHelperPath(mixed path) : void
since

3.0

Arguments

path

mixedA directory path or an array of paths.

addTemplatePath

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

addTemplatePath(mixed path) : void
since

3.0

Arguments

path

mixedA directory path or an array of paths.

assign

Assigns variables to the view script via differing strategies.

assign() : bool
deprecated

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);

since

3.0

deprecated

3.0 Use native PHP syntax.

Response

boolTrue on success, false on failure.

assignRef

Assign variable for the view (by reference).

assignRef(string key, mixed &val) : bool
deprecated

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;

since

3.0

deprecated

3.0 Use native PHP syntax.

Arguments

key

stringThe name for the reference in the view.

val

mixedThe referenced variable.

Response

boolTrue on success, false on failure.

display

Execute and display a template script.

display(string tpl = null) : mixed
see JViewLegacy::loadTemplate()
since

3.0

Arguments

tpl

stringThe name of the template file to parse; automatically searches through the template paths.

Response

mixedA string if successful, otherwise an Error object.

escape

Escapes a value for output in a view script.

escape(mixed var) : mixed

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

note

the ENT_COMPAT flag will be replaced by ENT_QUOTES in Joomla 4.0 to also escape single quotes

since

3.0

Arguments

var

mixedThe output to escape.

Response

mixedThe escaped value.

get

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

get(string property, string default = null) : mixed
since

3.0

Arguments

property

stringThe name of the method to call on the model or the property to get

default

stringThe name of the model to reference or the default value [optional]

Response

mixedThe return value of the method

getForm

Returns the form object

getForm() : mixed
since

3.2

Response

mixedA \JForm object on success, false on failure

getLayout

Get the layout.

getLayout() : string
since

3.0

Response

stringThe layout name

getLayoutTemplate

Get the layout template.

getLayoutTemplate() : string
since

3.0

Response

stringThe layout template name

getModel

Method to get the model object

getModel(string name = null) : mixed
since

3.0

Arguments

name

stringThe name of the model (optional)

Response

mixed\JModelLegacy object

getName

Method to get the view name

getName() : string

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

since

3.0

throws

\Exception

Response

stringThe name of the model

loadHelper

Load a helper file

loadHelper(string hlp = null) : void
since

3.0

Arguments

hlp

stringThe name of the helper source file automatically searches the helper paths and compiles as needed.

loadTemplate

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

loadTemplate(string tpl = null) : string
since

3.0

throws

\Exception

Arguments

tpl

stringThe name of the template source file; automatically searches the template paths and compiles as needed.

Response

stringThe output of the the template script.

setDocumentTitle

Sets the document title according to Global Configuration options

setDocumentTitle(string title) : void
since

3.6

Arguments

title

stringThe page title

setEscape

Sets the _escape() callback.

setEscape(mixed spec) : void
deprecated
since

3.0

deprecated

3.0 Override \JViewLegacy::escape() instead.

Arguments

spec

mixedThe callback for _escape() to use.

setLayout

Sets the layout name to use

setLayout(string layout) : string
since

3.0

Arguments

layout

stringThe layout name or a string in format