JView
Extends \JObjectBase class for a Joomla View
Class holding methods for displaying presentation data.
package |
Joomla.Platform |
---|---|
subpackage |
Application |
since |
11.1 |
Methods
__construct
Class constructor, overridden in descendant classes.
__construct(mixed $properties = null)
since |
11.1 |
---|
Arguments
- $properties
mixed
Either and associative array or another object to set the initial properties of the object.
__toString
Magic method to convert the object to a string gracefully.
__toString() : string
since |
11.1 |
---|---|
deprecated |
12.3 Classes should provide their own __toString() implementation. |
Response
string
The classname.
_addPath
Adds to the search path for templates and resources.
_addPath(string $type, mixed $path) : void
since |
11.1 |
---|
Arguments
- $type
string
The type of path to add.- $path
mixed
The 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 |
11.1 |
---|
Arguments
- $type
string
The resource type to create the filename for- $parts
array
An associative array of filename information
Response
string
The filename
_setPath
Sets an entire array of search paths for templates or resources.
_setPath(string $type, mixed $path) : void
since |
11.1 |
---|
Arguments
- $type
string
The type of path to set, typically 'template'.- $path
mixed
The 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 |
11.1 |
---|
Arguments
- $path
mixed
A directory path or an array of paths.
addTemplatePath
Adds to the stack of view script paths in LIFO order.
addTemplatePath(mixed $path) : void
since |
11.1 |
---|
Arguments
- $path
mixed
A directory path or an array of paths.
assign
Assigns variables to the view script via differing strategies.
assign() : boolean
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 JView;
// 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);
Response
boolean
True on success, false on failure.
assignRef
Assign variable for the view (by reference).
assignRef(string $key, &$val) : boolean
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->ref = &$var1;
since |
11.1 |
---|
Arguments
- $key
string
The name for the reference in the view.- $val
Response
boolean
True on success, false on failure.
def
Sets a default value if not alreay assigned
def(string $property, mixed $default = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
display
Execute and display a template script.
display(string $tpl = null) : mixed
see | \fetch() |
---|---|
since |
11.1 |
Arguments
- $tpl
string
The name of the template file to parse; automatically searches through the template paths.
Response
mixed
A string if successful, otherwise a JError object.
escape
Escapes a value for output in a view script.
escape(mixed $var) : mixed
If escaping mechanism is either htmlspecialchars or htmlentities, uses \$_encoding setting.
since |
11.1 |
---|
Arguments
- $var
mixed
The output to escape.
Response
mixed
The escaped value.
get
Returns a property of the object or the default value if the property is not set.
get(string $property, mixed $default = null) : mixed
since |
11.1 |
---|---|
see | \JObject::getProperties() |
Arguments
- $property
string
The name of the property.- $default
mixed
The default value.
Response
mixed
The value of the property.
getError
Get the most recent error message.
getError(integer $i = null, boolean $toString = true) : string
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $i
integer
Option error index.- $toString
boolean
Indicates if JError objects should return their error message.
Response
string
Error message
getErrors
Return all errors, if any.
getErrors() : array
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Response
array
Array of error messages or JErrors.
getLayout
Get the layout.
getLayout() : string
Response
string
The layout name
getLayoutTemplate
Get the layout template.
getLayoutTemplate() : string
Response
string
The layout template name
getModel
Method to get the model object
getModel(string $name = null) : mixed
since |
11.1 |
---|
Arguments
- $name
string
The name of the model (optional)
Response
mixed
JModel 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 |
11.1 |
---|
Response
string
The name of the model
getProperties
Returns an associative array of object properties.
getProperties(boolean $public = true) : array
since |
11.1 |
---|---|
see | \JObject::get() |
Arguments
- $public
boolean
If true, returns only the public properties.
Response
array
loadHelper
Load a helper file
loadHelper(string $hlp = null) : void
since |
11.1 |
---|
Arguments
- $hlp
string
The 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 |
11.1 |
---|
Arguments
- $tpl
string
The name of the template source file; automatically searches the template paths and compiles as needed.
Response
string
The output of the the template script.
set
Modifies a property of the object, creating it if it does not already exist.
set(string $property, mixed $value = null) : mixed
since |
11.1 |
---|
Arguments
- $property
string
The name of the property.- $value
mixed
The value of the property to set.
Response
mixed
Previous value of the property.
setError
Add an error message.
setError(string $error) : void
since |
11.1 |
---|---|
see | \JError |
deprecated |
12.3 JError has been deprecated |
Arguments
- $error
string
Error message.
setEscape
Sets the _escape() callback.
setEscape(mixed $spec) : void
since |
11.1 |
---|
Arguments
- $spec
mixed
The callback for _escape() to use.
setLayout
Sets the layout name to use
setLayout(string $layout) : string
since |
11.1 |
---|
Arguments
- $layout
string
The layout name or a string in format :
Response
string
Previous value.
setLayoutExt
Allows a different extension for the layout files to be used
setLayoutExt(string $value) : string
since |
11.1 |
---|
Arguments
- $value
string
The extension.
Response
string
Previous value
setModel
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.
setModel( &$model, boolean $default = false) : object
since |
11.1 |
---|
Arguments
- $model
- $default
boolean
Is this the default model?
Response
object
The added model.
setProperties
Set the object properties based on a named array/hash.
setProperties(mixed $properties) : boolean
since |
11.1 |
---|---|
see | \JObject::set() |
Arguments
- $properties
mixed
Either an associative array or another object.
Response
boolean
toString
Converts the object to a string (the class name).
toString() : string
Properties
_name
The name of the view
Type(s)
array
_models
Registered models
Type(s)
array
_basePath
The base path of the view
Type(s)
string
_defaultModel
The default model
Type(s)
string
_layout
Layout name
Type(s)
string
_layoutExt
Layout extension
Type(s)
string
_layoutTemplate
Layout template
Type(s)
string
_path
The set of search directories for resources (templates)
Type(s)
array
_template
The name of the default template source file.
Type(s)
string
_output
The output of the template script.
Type(s)
string
_escape
Callback for escaping.
Type(s)
string
_charset
Charset to use in escaping mechanisms; defaults to urf8 (UTF-8)
Type(s)
string
_errors
An array of error messages or Exception objects.