View
View
The View class is used to render views in the Hazaar MVC framework.
Properties
data
protected array $data
helpers
View Helpers.
protected array $helpers
application
protected Application $application
viewFile
public string $viewFile
helpersInit
Array for storing names of initialised helpers so we only initialise them once.
private array $helpersInit
prepared
private array $prepared
requiresParam
private $requiresParam
Methods
__construct
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$view | View | |
$inithelpers | array |
__get
public __get({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string |
__set
public __set({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | |
$value | mixed |
__isset
public __isset({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
__unset
public __unset({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
getViewPath
public getViewPath({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$view | string | |
$name | string |
load
public load({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$view | string |
getViewFile
Returns the filename that the view was loaded from.
public getViewFile({Array})
get
Helper/data accessor method.
public get({Array})
This will return a helper, if one exists with the name provided. Otherwise it will return any view data stored with the name.
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the name of the helper or view data key |
$default | mixed | if neither a helper or view data is found this default value will be returned |
set
Set view data value by key.
public set({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | The name of the view data |
$value | mixed | The value to set on the view data. Can be anything including strings, integers, arrays or objects. |
has
Tests if view data is set with the provided key.
public has({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | The name of the view data to look for |
remove
Remove view data.
public remove({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the name of the view data to remove |
populate
Populate view data from an array.
public populate({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$array | array |
extend
Extend/merge existing view data with an array.
public extend({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$array | array |
getData
Returns the entire current view data array.
public getData({Array})
addHelper
Adds a helper to the view.
public addHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | the name of the helper to add |
$args | array | the arguments to pass to the helper (optional) |
$alias | string | the alias for the helper (optional) |
hasHelper
Tests if a view helper has been loaded in this view.
public hasHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | The name of the view helper |
getHelpers
Returns a list of all currently loaded view helpers.
public getHelpers({Array})
removeHelper
Remove a loaded view helper.
public removeHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$helper | string | Returns true if the helper was unloaded. False if the view helper is not loaded to begin with. |
getHelper
Retrieve a loaded view helper object.
public getHelper({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | The name of the view helper |
initHelpers
Initialises the loaded view helpers.
public initHelpers({Array})
View helpers usually want to be initialised. This gives them a chance to require any scripts or set up any internal settings ready before execution of it's methods.
runHelpers
Runs loaded view helpers.
public runHelpers({Array})
render
Render the view.
public render({Array})
This method is responsible for loading the view files from disk, rendering it and returning it's output.
Parameters
Parameter | Type | Description |
---|---|---|
$data | array | The data to pass to the view. This data will be merged with any existing view data. |
partial
Render a partial view in the current view.
public partial({Array})
This method can be called from inside a view source file to include another view source file.
Parameters
Parameter | Type | Description |
---|---|---|
$view | string | The name of the view to include, relative to the current view. This means that if the view is in the same |
directory, it is possible to just name the view. If it is in a sub directly, include the path relative
to the current view. Using parent references (..) will also work. |
| $data
| bool
| The data parameter can be either TRUE to indicate that all view data should be passed to the partial view, or an array of data to pass instead. By default, no view data is passed to the partial view. | | $mergedata
| bool
| |
preparePartial
Prepare a partial view for later rendering.
public preparePartial({Array})
This method is similar to the partial
method, but instead of rendering the view immediately, it will prepare the view for rendering later.
Parameters
Parameter | Type | Description |
---|---|---|
$view | string | The name of the view to include, relative to the current view. This means that if the view is in the same |
directory, it is possible to just name the view. If it is in a sub directly, include the path relative
to the current view. Using parent references (..) will also work. |
| $data
| bool
| The data parameter can be either TRUE to indicate that all view data should be passed to the |
setRequiresParam
Add a required parameter to the view.
public setRequiresParam({Array})
This is used to add a required parameter to the view. If the parameter is not set when the view is rendered, an exception will be thrown.
Parameters
Parameter | Type | Description |
---|---|---|
$array | array | an array of required parameter names |
partialLoop
Render a partial view multiple times on an array.
public partialLoop({Array})
This basically calls $this->partial
for each element in an array
Parameters
Parameter | Type | Description |
---|---|---|
$view | string | the partial view to render |
$data | array | a data array, usually multi-dimensional, that each element will be passed to the partial view |
url
Generates a URL based on the provided controller, action, parameters, and absolute flag.
public url({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$controller | string | the name of the controller |
$action | string | the name of the action |
$params | array | an array of parameters to be included in the URL |
$absolute | bool | determines whether the generated URL should be absolute or relative |
date
Returns a date string formatted to the current set date format.
public date({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$date | string |
timestamp
public timestamp({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$value | string |
datetime
public datetime({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$value | mixed | |
$format | string |
offsetExists
public offsetExists({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
offsetGet
public offsetGet({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
offsetSet
public offsetSet({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$offset | mixed |
findHelper
Find a helper class for the given name.
private findHelper({Array})
This method searches for view helper classes in the specified search paths. The order of the search paths is important because it allows apps to override built-in helpers.
Parameters
Parameter | Type | Description |
---|---|---|
$name | string | the name of the helper class to find |
Generated by Hazaar API Doc Generator