Documentation

ViewInterface

Template processor

This class is used for server side HTML rendering with the help of PHP.

Table of Contents

addFolder()  : void
Adds a view folder
addScript()  : void
Adds a script for the view
addStyle()  : void
Adds a style for the view
block()  : string
Returns with the content of a block
endBlock()  : void
Ends a block
fetch()  : string
Fetches a template with variables
folder()  : string
Returns with the folder path by namespace
get()  : mixed
Returns with a view variable value by name
layout()  : string
Returns with the current layout
scripts()  : array<string|int, mixed>
Returns with the scripts in [src => [attributes]] array
set()  : void
Sets a view variable
setTheme()  : void
Sets the theme path for overriding templates
startBlock()  : void
Starts a block
styles()  : array<string|int, mixed>
Returns with the styles in [src => [attributes]] array
theme()  : string
Returns with the theme path
useLayout()  : void
Sets the layout so after the template was rendered it will render this layout.

Methods

addFolder()

Adds a view folder

public addFolder(string $namespace, string $path) : void

For example, if the app.root_path config value is '/var/www/example.com', and you have the following code:

$view->addFolder('folder', '~/views/example');
$view->fetch('folder:index');

will fetch the '/var/www/example.com/views/example/index.phtml'.

The $path should NOT end with a '/'

Parameters
$namespace : string
$path : string
Return values
void

addScript()

Adds a script for the view

public addScript(string $src[, array<string|int, mixed> $attributes = [] ]) : void
Parameters
$src : string
$attributes : array<string|int, mixed> = []
Return values
void

addStyle()

Adds a style for the view

public addStyle(string $src[, array<string|int, mixed> $attributes = [] ]) : void
Parameters
$src : string
$attributes : array<string|int, mixed> = []
Return values
void

block()

Returns with the content of a block

public block(string $name) : string
Parameters
$name : string
Return values
string

endBlock()

Ends a block

public endBlock() : void

If the block has content, the new content will be appended to the block.

Return values
void

fetch()

Fetches a template with variables

public fetch(string $__viewPath[, array<string|int, mixed> $__vars = [] ]) : string
Parameters
$__viewPath : string
$__vars : array<string|int, mixed> = []
Return values
string

folder()

Returns with the folder path by namespace

public folder(string $namespace) : string
Parameters
$namespace : string
Return values
string

get()

Returns with a view variable value by name

public get(string $name[, mixed $default = null ]) : mixed
Parameters
$name : string
$default : mixed = null
Return values
mixed

layout()

Returns with the current layout

public layout() : string
Return values
string

scripts()

Returns with the scripts in [src => [attributes]] array

public scripts() : array<string|int, mixed>
Return values
array<string|int, mixed>

set()

Sets a view variable

public set(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Return values
void

setTheme()

Sets the theme path for overriding templates

public setTheme(string $path) : void
Parameters
$path : string
Return values
void

startBlock()

Starts a block

public startBlock(string $name) : void

If the block has content, when the endBlock() will be called the content will be appended to the block.

Parameters
$name : string
Return values
void

styles()

Returns with the styles in [src => [attributes]] array

public styles() : array<string|int, mixed>
Return values
array<string|int, mixed>

theme()

Returns with the theme path

public theme() : string
Return values
string

useLayout()

Sets the layout so after the template was rendered it will render this layout.

public useLayout(string $path) : void

The path can contain a namespace if a folder was added with that namespace, for example:

$view->addFolder('folder', 'views/example');
$view->useLayout('folder:layout');

will render the 'views/example/layout.phtml'.

Parameters
$path : string
Return values
void

Search results