View
View
The View class is used to render views in the Hazaar framework.
Properties
application
The application object.
public Application $applicationdata
Data that is accessible from the view.
protected array $datahelpers
View Helpers.
protected array $helpersfunctionHandlers
Array of function handlers. These can be either closures or objects that provide public methods.
protected array $functionHandlersfunctions
Array of functions that can be called from the view.
protected array $functionsviewFile
public string $viewFilehelpersInit
Array for storing names of initialised helpers so we only initialise them once.
private array $helpersInitMethods
__construct
View constructor.
public __construct(View $view, array $viewData): voidParameters
| Parameter | Type | Description |
|---|---|---|
$view | View | The name of the view to load or a View object to clone |
$viewData | array | The data to pass to the view |
__get
Magic method to get view data.
public __get(string $helper): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$helper | string |
__set
Magic method to set view data.
public __set(string $key, mixed $value): voidParameters
| 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. |
__isset
Magic method to test if view data is set.
public __isset(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The name of the view data to look for |
__unset
Magic method to remove view data.
public __unset(string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the name of the view data to remove |
__call
Magic method to call a function from the view.
public __call(string $method, array $args): mixedThis method will call a function from the view. The function must be registered with the view using the registerFunction or registerFunctionHandler methods.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The name of the method to call |
$args | array | The arguments to pass to the method |
getViewPath
Returns the path to a view file.
public getViewPath(string $view, string $name): ?stringThis method will search for a view file in the application view path and the support view path.
Parameters
| Parameter | Type | Description |
|---|---|---|
$view | string | the name of the view to find |
$name | string | the name of the view that was found |
load
Load a view file.
public load(string $view): voidThis method will load a view file from disk. The view file can be either a PHP file or a Smarty template file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$view | string | the name of the view to load |
getViewFile
Returns the filename that the view was loaded from.
public getViewFile(): stringget
Helper/data accessor method.
public get(string $key, mixed $default): voidThis 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(string $key, mixed $value): voidParameters
| 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(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The name of the view data to look for |
remove
Remove view data.
public remove(string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the name of the view data to remove |
populate
Populate view data from an array.
public populate(array $array): boolParameters
| Parameter | Type | Description |
|---|---|---|
$array | array |
extend
Extend/merge existing view data with an array.
public extend(array $array): boolParameters
| Parameter | Type | Description |
|---|---|---|
$array | array |
getData
Returns the entire current view data array.
public getData(): voidaddHelper
Adds a helper to the view.
public addHelper(string $helper, array $args, ?string $alias): boolParameters
| 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(string $helper): boolParameters
| Parameter | Type | Description |
|---|---|---|
$helper | string | The name of the view helper |
getHelpers
Returns a list of all currently loaded view helpers.
public getHelpers(): voidremoveHelper
Remove a loaded view helper.
public removeHelper(string $helper): boolParameters
| 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(string $key): ?HelperParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | The name of the view helper |
initHelpers
Initialises the loaded view helpers.
public initHelpers(): voidView 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(): voidrender
Render the view.
public render(?array $data): stringThis 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. |
offsetExists
public offsetExists(mixed $offset): boolParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetGet
public offsetGet(mixed $offset): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
offsetSet
public offsetSet(mixed $offset, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed | |
$value | mixed |
offsetUnset
public offsetUnset(mixed $offset): voidParameters
| Parameter | Type | Description |
|---|---|---|
$offset | mixed |
registerFunctionHandler
Register a function handler.
public registerFunctionHandler(mixed $handler): voidFunction handlers are used to handle custom functions in the view template. Unlike custom functions, function handlers are objects that provide public methods that can be called from the view template.
Smarty:
{$functionName param1="value" param2="value"}PHP:
<?php $this->functionName('param1') ?>The function will be called with the parameters as an array. The function must return a string which will be inserted into the view at the point the function was called.
Parameters
| Parameter | Type | Description |
|---|---|---|
$handler | mixed | The function handler object to register |
registerFunction
Register a custom function with the view.
public registerFunction(string $name, callable $function): voidCustom functions are functions that can be called from within the view. The function can be called using the syntax:
Smarty:
{$functionName param1="value" param2="value"}PHP:
<?php $this->functionName('param1') ?>The function will be called with the parameters as an array. The function must return a string which will be inserted into the view at the point the function was called.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the function to register |
$function | callable | The function to call when the function is called in the view |
setFunctionHandlers
Sets the function handlers, overwriting any existing handlers.
public setFunctionHandlers(array $handlers): voidParameters
| Parameter | Type | Description |
|---|---|---|
$handlers | array |
setFunctions
Sets the functions, overwriting any existing functions.
public setFunctions(array $functions): voidParameters
| Parameter | Type | Description |
|---|---|---|
$functions | array | The functions to set |
findHelper
Find a helper class for the given name.
private findHelper(string $name): ?stringThis 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 on Mon, 27 Oct 2025 13:01:29 +0000