View
class View
Encapsulates data for displaying a form or result of a form submission and uses the Twig template engine to render its output.
This class manages the parameters that are involved in the form (which should implement ParameterInterface) and allows for a general PHP redirect. It initializes the Twig template engine and passes the stored parameters to it. Twig is then used to render and display the form as specified in the main template. This view also passes on the $_SERVER superglobal to the template (accessible as "_server"). Exceptions generated by Twig are shown as errors and logged accordingly.
Properties
private string | $templateName | The name of the view (the template file that is to be rendered). | |
private string | $templateDirectory | The relative path to the directory where the template files are stored. | |
private string | $templateCacheDirectory | The relative path where cached/compiled templates are to be stored. | |
private array | $params | An array of parameters used for display. | |
private FilesystemLoader | $loader | The Twig loader instance. | |
private Environment | $twig | The main instance of the Twig template engine (environment). |
Methods
Creates a new view with the main template to be displayed, the path to the template and compiled templates directory as well as parameters of the form. Also initializes the Twig template engine with caching and auto reload enabled.
Returns the name of the main template that's being used for display.
Returns the supplied parameters.
Allows to add or redefine parameters when the view object already exists. This avoids having to create a completely new view object just because one parameter has changed or needs to be added. This method first checks if a parameter with the given name is already stored within the view. If so, it updates its value with the one supplied in $param. If the parameter is not present in the view, it is being added.
Displays the current view. Iterates over all the parameters and stores them in a temporary, associative array.
Performs a generic redirect using header(). GET-Parameters may optionally be supplied as an associative array.
Details
at line 84
__construct(string $templateName, string $templateDirectory = "templates", string $templateCacheDirectory = "templates_c", array $params = [])
Creates a new view with the main template to be displayed, the path to the template and compiled templates directory as well as parameters of the form. Also initializes the Twig template engine with caching and auto reload enabled.
at line 107
string
getTemplateName()
Returns the name of the main template that's being used for display.
at line 116
array
getParameters()
Returns the supplied parameters.
at line 128
setParameter(ParameterInterface $param)
Allows to add or redefine parameters when the view object already exists. This avoids having to create a completely new view object just because one parameter has changed or needs to be added. This method first checks if a parameter with the given name is already stored within the view. If so, it updates its value with the one supplied in $param. If the parameter is not present in the view, it is being added.
at line 145
display()
Displays the current view. Iterates over all the parameters and stores them in a temporary, associative array.
Twig then displays the main template, using the array with the parameters. Exceptions generated by Twig are shown as errors and logged accordingly for simplification.
at line 176
static
redirectTo(string $location, array $queryParameters = null)
Performs a generic redirect using header(). GET-Parameters may optionally be supplied as an associative array.