Documentation

View
in package
implements RendererInterface

Class View

Interfaces, Classes and Traits

RendererInterface
Interface RendererInterface

Table of Contents

$config  : View
$currentSection  : string|null
The name of the current section being rendered, if any.
$data  : array<string|int, mixed>
Data that is made available to the Views.
$debug  : bool
Should we store performance info?
$layout  : string|null
The name of the layout being used, if any.
$loader  : FileLocator
Instance of FileLocator for when we need to attempt to find a view that's not in standard place.
$logger  : LoggerInterface
Logger instance.
$performanceData  : array<string|int, mixed>
Cache stats about our performance here, when CI_DEBUG = true
$renderVars  : array<string|int, mixed>
The render variables
$saveData  : bool
Whether data should be saved between renders.
$sections  : array<string|int, mixed>
Holds the sections and their data.
$sectionStack  : array<string|int, string>
The name of the current section being rendered, if any.
$tempData  : mixed
Merge savedData and userData
$viewPath  : string
The base directory to look in for our Views.
$viewsCount  : int
Number of loaded views
__construct()  : mixed
Constructor
endSection()  : void
Captures the last section
excerpt()  : string
Extract first bit of a long string and add ellipsis
extend()  : void
Specifies that the current view should extend an existing layout.
getData()  : array<string|int, mixed>
Returns the current data that will be displayed in the view.
getPerformanceData()  : array<string|int, mixed>
Returns the performance data that might have been collected during the execution. Used primarily in the Debug Toolbar.
include()  : string
Used within layout views to include additional views.
render()  : string
Builds the output based upon a file name and any data that has already been set.
renderSection()  : mixed
Renders a section's contents.
renderString()  : string
Builds the output based upon a string and any data that has already been set.
resetData()  : RendererInterface
Removes all of the view data from the system.
section()  : void
Starts holds content for a section within the layout.
setData()  : RendererInterface
Sets several pieces of view data at once.
setVar()  : RendererInterface
Sets a single piece of view data.
logPerformance()  : void
Logs performance data for rendering a view.

Properties

$currentSection

The name of the current section being rendered, if any.

protected string|null $currentSection
Tags
deprecated

$data

Data that is made available to the Views.

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

$debug

Should we store performance info?

protected bool $debug = false

$layout

The name of the layout being used, if any.

protected string|null $layout

Set by the extend method used within views.

$loader

Instance of FileLocator for when we need to attempt to find a view that's not in standard place.

protected FileLocator $loader

$performanceData

Cache stats about our performance here, when CI_DEBUG = true

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

$renderVars

The render variables

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

$saveData

Whether data should be saved between renders.

protected bool $saveData

$sections

Holds the sections and their data.

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

$sectionStack

The name of the current section being rendered, if any.

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

$tempData

Merge savedData and userData

protected mixed $tempData = null

$viewPath

The base directory to look in for our Views.

protected string $viewPath

$viewsCount

Number of loaded views

protected int $viewsCount = 0

Methods

__construct()

Constructor

public __construct(View $config[, string|null $viewPath = null ][, FileLocator|null $loader = null ][, bool|null $debug = null ][, LoggerInterface $logger = null ]) : mixed
Parameters
$config : View
$viewPath : string|null = null
$loader : FileLocator|null = null
$debug : bool|null = null
$logger : LoggerInterface = null
Return values
mixed

endSection()

Captures the last section

public endSection() : void
Tags
throws
RuntimeException
Return values
void

excerpt()

Extract first bit of a long string and add ellipsis

public excerpt(string $string[, int $length = 20 ]) : string
Parameters
$string : string
$length : int = 20
Return values
string

extend()

Specifies that the current view should extend an existing layout.

public extend(string $layout) : void
Parameters
$layout : string
Return values
void

getData()

Returns the current data that will be displayed in the view.

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

getPerformanceData()

Returns the performance data that might have been collected during the execution. Used primarily in the Debug Toolbar.

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

include()

Used within layout views to include additional views.

public include(string $view[, array<string|int, mixed>|null $options = null ][, bool $saveData = true ]) : string
Parameters
$view : string
$options : array<string|int, mixed>|null = null
$saveData : bool = true
Return values
string

render()

Builds the output based upon a file name and any data that has already been set.

public render(string $view[, array<string|int, mixed>|null $options = null ][, bool|null $saveData = null ]) : string

Valid $options:

  • cache Number of seconds to cache for
  • cache_name Name to use for cache
Parameters
$view : string

File name of the view source

$options : array<string|int, mixed>|null = null

Reserved for 3rd-party uses since it might be needed to pass additional info to other template engines.

$saveData : bool|null = null

If true, saves data for subsequent calls, if false, cleans the data after displaying, if null, uses the config setting.

Return values
string

renderSection()

Renders a section's contents.

public renderSection(string $sectionName) : mixed
Parameters
$sectionName : string
Return values
mixed

renderString()

Builds the output based upon a string and any data that has already been set.

public renderString(string $view[, array<string|int, mixed>|null $options = null ][, bool|null $saveData = null ]) : string

Cache does not apply, because there is no "key".

Parameters
$view : string

The view contents

$options : array<string|int, mixed>|null = null

Reserved for 3rd-party uses since it might be needed to pass additional info to other template engines.

$saveData : bool|null = null

If true, saves data for subsequent calls, if false, cleans the data after displaying, if null, uses the config setting.

Return values
string

section()

Starts holds content for a section within the layout.

public section(string $name) : void
Parameters
$name : string

Section name

Return values
void

setData()

Sets several pieces of view data at once.

public setData([array<string|int, mixed> $data = [] ][, string $context = null ]) : RendererInterface
Parameters
$data : array<string|int, mixed> = []
$context : string = null

The context to escape it for: html, css, js, url If null, no escaping will happen

Return values
RendererInterface

setVar()

Sets a single piece of view data.

public setVar(string $name[, mixed $value = null ][, string $context = null ]) : RendererInterface
Parameters
$name : string
$value : mixed = null
$context : string = null

The context to escape it for: html, css, js, url If null, no escaping will happen

Return values
RendererInterface

logPerformance()

Logs performance data for rendering a view.

protected logPerformance(float $start, float $end, string $view) : void
Parameters
$start : float
$end : float
$view : string
Return values
void

Search results