Class View
View
The view is responsible for rendering a template. The view should subclass
\Slim\View and implement this interface:
public render(string $template);
This method should render the specified template and return the resultant
string.
Methods summary
public
|
#
__construct( )
Constructor
This is empty but may be implemented in a subclass
|
public
mixed
|
#
getData( string|null $key = null )
Get data
Parameters
Returns
mixed If key is null, array of template data; If key exists, value of datum with key;
If key does not exist, null;
|
public
|
#
setData( )
Set data
If two arguments: A single datum with key is assigned value;
$view->setData('color', 'red');
If one argument: Replace all data with provided array keys and values;
$view->setData(array('color' => 'red', 'number' => 1));
Throws
|
public
|
#
appendData( array $data )
Append new data to existing template data
Append new data to existing template data
Parameters
Throws
|
public
string|null
|
#
getTemplatesDirectory( )
Get templates directory
Returns
string|null Path to templates directory without trailing slash; Returns null if templates
directory not set;
|
public
|
|
public
|
#
setTemplate( string $template )
Set template
Parameters
- $template
string $template
Throws
RuntimeExceptionIf template file does not exist DEPRECATION WARNING! This method will be removed
in the near future.
|
public
|
#
display( string $template )
Display template
This method echoes the rendered template to the current output buffer
Parameters
- $template
string $template Pathname of template file relative to templates directoy
|
public
string
|
#
fetch( string $template )
Fetch rendered template
This method returns the rendered template
Parameters
- $template
string $template Pathname of template file relative to templates directory
Returns
string
|
public
string
|
#
render( string $template )
Render template
Parameters
- $template
string $template Pathname of template file relative to templates directory
Returns
string DEPRECATION WARNING! Use \Slim\View::fetch to return a rendered
template instead of \Slim\View::render.
|
Properties summary
protected
string
|
$templatePath
|
'' |
#
Absolute or relative filesystem path to a specific template
DEPRECATION WARNING! This variable will be removed in the near future
Absolute or relative filesystem path to a specific template
DEPRECATION WARNING! This variable will be removed in the near future
|
protected
array
|
$data
|
array() |
#
Associative array of template variables
Associative array of template variables
|
protected
string
|
$templatesDirectory
|
|
#
Absolute or relative path to the application's templates directory
Absolute or relative path to the application's templates directory
|