ViewRenderer
ViewRenderer
Class ViewRenderer.
Properties
view
public View $viewdata
The data to pass to the view.
private array $datafunctionHandlers
The function handlers that are registered with the view renderer and
private array $functionHandlerscan be called from the view template.
functions
The custom functions that are registered with the view renderer and
private array $functionscan be called from the view template.
Methods
__set
Magic method to set the value of a data property.
public __set(string $key, mixed $value): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | |
$value | mixed |
__isset
Magic method to check if a property is set.
public __isset(string $name): boolParameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
__unset
Magic method to unset a property.
public __unset(string $name): voidParameters
| Parameter | Type | Description |
|---|---|---|
$name | string |
exec
Executes the view renderer.
public exec(HTML $response): voidParameters
| Parameter | Type | Description |
|---|---|---|
$response | HTML |
addHelper
Adds a helper to the view renderer.
public addHelper(string $helper, array $args, ?string $alias): boolParameters
| Parameter | Type | Description |
|---|---|---|
$helper | string | the name of the helper to add |
$args | array | an optional array of arguments to pass to the helper |
$alias | string | an optional alias for the helper |
getHelpers
Retrieves the helpers associated with the current view.
public getHelpers(): voidremoveHelper
Removes a helper from the view renderer.
public removeHelper(string $name): voidParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the helper to remove |
__get
Magic method to get the value of a property.
public __get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the name of the property to get |
populate
Populates the view renderer with data.
public populate(array $array): voidParameters
| Parameter | Type | Description |
|---|---|---|
$array | array | the array of data to populate the view renderer with |
extend
Extends the data available on any defined views.
public extend(array $array): voidParameters
| Parameter | Type | Description |
|---|---|---|
$array | array | the array of data to extend the view renderer with |
hasView
Checks if a view exists.
public hasView(string $view): boolParameters
| Parameter | Type | Description |
|---|---|---|
$view | string | the name of the view to check |
layout
Sets the layout for the view.
public layout(string $view): voidIf the current view is an instance of Layout, it loads the specified layout. Otherwise, if the specified layout is not an instance of Layout, it creates a new Layout instance. Finally, it sets the view to the specified layout.
Parameters
| Parameter | Type | Description |
|---|---|---|
$view | string | the layout or view to set |
setNoLayout
Sets the view renderer to disable layout rendering.
public setNoLayout(): voidThis method sets the view property to null, which indicates that the layout rendering should be disabled. When the layout rendering is disabled, only the view template will be rendered without any surrounding layout.
view
Renders a view.
public view(View $view, array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$view | View | The view to render. It can be either a string representing the view file path or an instance of the View class. |
$data | array | The data to pass to the view |
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 |
render
Renders a view and returns the rendered output as a string.
private render(View $view): stringParameters
| Parameter | Type | Description |
|---|---|---|
$view | View | the view object to render |
Generated by Hazaar API Doc Generator on Tue, 30 Sep 2025 00:01:37 +0000