Documentation

View
in package
implements ViewInterface

Interfaces, Classes, Traits and Enums

ViewInterface
Template processor

Table of Contents

CONFIG_DEFAULT_FOLDER  = 'view.default_folder'
$blockQueue  : array<string|int, mixed>
Holds the blocks queue for start/end block functions
$blocks  : array<string|int, mixed>
Holds the content of the blocks by name
$config  : ConfigInterface
$data  : array<string|int, mixed>
Holds the view variables
$folders  : array<string|int, mixed>
Stores the paths for the folders by namespace
$functionsIncluded  : bool
The functions were included?
$layout  : string
The layout for the currently fetched template
$scripts  : array<string|int, mixed>
Holds the scripts for the view
$styles  : array<string|int, mixed>
Holds the styles for the view
$theme  : string
The theme path for overriding templates
__construct()  : mixed
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.
getRealPath()  : string
Returns with the real path to the template file
includeFunctions()  : void
Includes the functions.php of the theme, of the app and of the framework

Constants

CONFIG_DEFAULT_FOLDER

public mixed CONFIG_DEFAULT_FOLDER = 'view.default_folder'

Properties

$blockQueue

Holds the blocks queue for start/end block functions

protected array<string|int, mixed> $blockQueue = []

$blocks

Holds the content of the blocks by name

protected array<string|int, mixed> $blocks = []

$data

Holds the view variables

protected array<string|int, mixed> $data = []

$folders

Stores the paths for the folders by namespace

protected array<string|int, mixed> $folders = []

$functionsIncluded

The functions were included?

protected bool $functionsIncluded = false

$layout

The layout for the currently fetched template

protected string $layout = ''

$scripts

Holds the scripts for the view

protected array<string|int, mixed> $scripts = []

$styles

Holds the styles for the view

protected array<string|int, mixed> $styles = []

$theme

The theme path for overriding templates

protected string $theme = ''

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

getRealPath()

Returns with the real path to the template file

protected getRealPath(string $path) : string
  • If the path doesn't contain a namespace it will use the view.default_folder config value to determine the path for the folder.
  • If the path contains a namespace it will use the folder of the namespace.
  • If the view has a theme, that path will be checked first, so the theme can override every template.

For example if you added a folder with namespace 'folder':

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

and the app.root_path config value is '/var/www/example.com' the result will be '/var/www/example.com/views/example/index.phtml'

Parameters
$path : string
Tags
throws
MicroException

If the view path has a namespace but a folder wasn't added for it

Return values
string

includeFunctions()

Includes the functions.php of the theme, of the app and of the framework

protected includeFunctions() : void
Return values
void

Search results