HTMLViewRenderer
extends CoreObject
in package
implements
ViewRenderer
The default implementation of the ViewRenderer interface.
Renders HTML with templated header and footer Would make a good starting point for integration with front end frameworks like Bootstrap
Tags
Table of Contents
Interfaces
- ViewRenderer
- An interface defining a ViewRenderer ViewRenderers are utilized by controllers and handle the presentation of data to the user Built in implementations are HTMLViewRenderer and JSONViewRenderer
Properties
- $appContext : array<string|int, mixed>
- $variables : array<string|int, mixed>
- $viewDirectory : string
- $viewFile : string
- $viewPath : string
Methods
- __construct() : mixed
- Initializes the ViewRenderer with the state of the application
- getAppConfiguration() : array<string|int, mixed>
- Provides a single instance of the global app configuration to all extenders of CoreObject
- getAppContextProperty() : mixed|null
- Returns the requested appContext variable
- getLogger() : Logger
- Provides a single instance of a configured Logger to all extenders of CoreObject
- getViewVariable() : mixed
- Get a single view variable by its name
- getViewVariables() : array<string|int, mixed>
- Get the registered view variables
- registerAppContextProperty() : void
- Register a reference to a variable for the views geared toward the app environment (User session, server paths, config)
- registerViewVariable() : void
- Push to the array of registered view variables
- renderView() : void
- Displays the response as HTML
- setPage() : void
- Registers the current page as an appContext variable
- setView() : bool
- Sets the view tasked with presenting the page specific response
- setViewDirectory() : void
- Allows for defining a subdirectory for views which will be appended to the primary view path.
- setViewVariables() : void
- Set all variables associated with the view at once.
- getAdminViewPath() : string
- getViewDirectory() : string
- Gets the (optional) subdirectory for views which will be appended to the primary view path.
- getViewFile() : string
- getViewPath() : string
- setViewPath() : void
Properties
$appContext
private
array<string|int, mixed>
$appContext
= null
An array of data for the views geared toward the app environment (User session, server paths, config)
$variables
private
array<string|int, mixed>
$variables
= array()
An array of application data to provide to the views
$viewDirectory
private
string
$viewDirectory
= ''
An optional subdirectory within the $viewPath that contains a collection of related views
$viewFile
private
string
$viewFile
= null
The filename of the view to load
$viewPath
private
string
$viewPath
= ''
The directory path to the views
Methods
__construct()
Initializes the ViewRenderer with the state of the application
public
__construct(User $globalUser, array<string|int, SitePage> $pages, array<string|int, mixed> $data, string $controllerName) : mixed
Parameters
getAppConfiguration()
Provides a single instance of the global app configuration to all extenders of CoreObject
public
getAppConfiguration() : array<string|int, mixed>
Return values
array<string|int, mixed>getAppContextProperty()
Returns the requested appContext variable
public
getAppContextProperty(string $name) : mixed|null
Parameters
- $name : string
-
The name of the variable
Return values
mixed|null —Returns the variable or null if it was not found
getLogger()
Provides a single instance of a configured Logger to all extenders of CoreObject
public
getLogger() : Logger
Return values
LoggergetViewVariable()
Get a single view variable by its name
public
getViewVariable(mixed $name) : mixed
Parameters
- $name : mixed
-
The name of the variable
Return values
mixed —$viewVariable
getViewVariables()
Get the registered view variables
public
getViewVariables() : array<string|int, mixed>
Return values
array<string|int, mixed> —$viewVariables
registerAppContextProperty()
Register a reference to a variable for the views geared toward the app environment (User session, server paths, config)
public
registerAppContextProperty(string $name, mixed $data) : void
Parameters
- $name : string
-
The name of the variable
- $data : mixed
-
The value of the variable
registerViewVariable()
Push to the array of registered view variables
public
registerViewVariable(mixed $name, mixed $data) : void
Parameters
- $name : mixed
-
- The name of the variable
- $data : mixed
-
- The value(s) of the view variable
renderView()
Displays the response as HTML
public
renderView() : void
setPage()
Registers the current page as an appContext variable
public
setPage(SitePage $page) : void
Parameters
- $page : SitePage
-
The current SitePage
setView()
Sets the view tasked with presenting the page specific response
public
setView(string $viewFile[, bool $isAdmin = false ]) : bool
Parameters
- $viewFile : string
-
The name of the view (This ViewRenderer will append '.view.php' to generate a filename
- $isAdmin : bool = false
-
Define the view as admin or standard (determines the location of the viewFile)
Return values
bool —Returns true if the file was found, false if not found
setViewDirectory()
Allows for defining a subdirectory for views which will be appended to the primary view path.
public
setViewDirectory(string $directoryName) : void
For example, all views for a Controller can be put in a view subdirectory, and that Controller will set the viewDirectory to match that location.
Parameters
- $directoryName : string
-
The subdirectory location of the view files within the primary views directory
setViewVariables()
Set all variables associated with the view at once.
public
setViewVariables(mixed $data) : void
This can also be expected to overwrite previously set view variables
Parameters
- $data : mixed
getAdminViewPath()
protected
getAdminViewPath() : string
Return values
string —The full path to the admin views directory (by default, this is the same as the standard path)
getViewDirectory()
Gets the (optional) subdirectory for views which will be appended to the primary view path.
protected
getViewDirectory() : string
Return values
stringgetViewFile()
protected
getViewFile() : string
Return values
string —The $viewFile
getViewPath()
protected
getViewPath() : string
Return values
string —The full directory path to the views
setViewPath()
protected
setViewPath(string $viewPath) : void
Parameters
- $viewPath : string
-
Sets the full directory path to the views