PHP Class FOF30\View\View

A generic MVC view implementation
Mostrar archivo Open project: akeeba/fof Class Usage Examples

Public Properties

Property Type Description
$baseurl
$doTask string Currently public, it should be reduced to protected in the future
$task string Currently public, it should be reduced to protected in the future

Protected Properties

Property Type Description
$_tempFilePath null Used when loading template files to avoid variable scope issues
$config array A cached copy of the configuration
$container FOF30\Container\Container The container attached to this view
$defaultModel string The default model
$doPostRender boolean Should I run the post-render step?
$doPreRender boolean Should I run the pre-render step?
$layout string Layout name
$layoutTemplate string Layout template
$modelInstances array Registered models
$name array The name of the view
$output string The output of the template script.
$renderCount integer The number of active rendering operations.
$sectionStack array The stack of in-progress sections.
$sections array All of the finished, captured sections.
$template string The name of the default template source file.
$templatePaths array The set of search directories for view templates
$viewEngineMap array Maps view template extensions to view engine classes
$viewFinder ViewTemplateFinder The object used to locate view templates in the filesystem
$viewTemplateAliases array array('userProfile' => 'site://com_foobar/users/profile') allows you to do something like $this->loadAnyTemplate('userProfile') to display the frontend view template site://com_foobar/users/profile. You can also alias one view template with another, e.g. 'site://com_something/users/profile' => 'admin://com_foobar/clients/record'

Public Methods

Method Description
__construct ( Container $container, array $config = [] ) : View Constructor.
__get ( string $name ) : mixed | null Magic get method. Handles magic properties: $this->input mapped to $this->container->input
addCssFile ( string $uri, string $version = null, string $type = 'text/css', string $media = null, array $attribs = [] ) Add a CSS file to the page generated by the CMS
addCssInline ( string $css, string $type = 'text/css' ) Adds an inline stylesheet (inline CSS) to the page header
addJavascriptFile ( string $uri, string $version = null, string $type = 'text/javascript', boolean $defer = false, boolean $async = false ) Add a JS script file to the page generated by the CMS.
addJavascriptInline ( string $script, string $type = 'text/javascript' ) Adds an inline JavaScript script to the page header
addLess ( string $uri, string $cssUri, string $version = null, string $type = 'text/css', string $media = null, array $attribs = [] ) Compile a LESS file into CSS and add it to the page generated by the CMS.
alias ( string $viewTemplate, string $alias ) : void Add an alias for a view template.
appendSection ( ) : string Stop injecting content into a section and append it.
decrementRender ( ) : void Decrement the rendering counter.
display ( string $tpl = null ) : boolean Overrides the default method to execute and display a template script.
doneRendering ( ) : boolean Check if there are no active render operations.
escape ( mixed $var ) : mixed Escapes a value for output in a view script.
flushSections ( ) : void Flush all of the section contents.
flushSectionsIfDoneRendering ( ) : void Flush all of the section contents if done rendering.
get ( string $property, string $default = null, string $modelName = null ) : mixed Method to get data from a registered model or a property of the view
getContainer ( ) : Container Returns a reference to the container attached to this View
getDoTask ( )
getLayout ( ) : string Get the layout.
getLayoutTemplate ( ) : string Get the layout template.
getModel ( string $name = null ) : Model Returns a named Model object
getName ( ) : string Method to get the view name
getTask ( )
incrementRender ( ) : void Increment the rendering counter.
loadAnyTemplate ( string $uri = '', array $forceParams = [], callable $callback = null ) : string Loads a template given any path. The path is in the format componentPart://componentName/viewName/layoutName, for example site:com_example/items/default admin:com_example/items/default_subtemplate auto:com_example/things/chair any:com_example/invoices/printpreview
loadHelper ( string $helperClass = null ) : void Load a helper file
loadTemplate ( string $tpl = null, boolean $strict = false ) : mixed Our function uses loadAnyTemplate to provide smarter view template loading.
populateFromModel ( Model $model ) This method is called by the Renderer when an XML form includes a view template. The $model variable contains the Model object instance used by the form. You can override this method to populate your View class with data from that model.
renderEach ( string $viewTemplate, array $data, string $eachItemName, string $empty = 'raw|' ) : string Go through a data array and render a subtemplate against each record (think master-detail views). This is accessible through Blade templates as @each
setDefaultModel ( Model &$model ) Pushes the default Model to the View
setDefaultModelName ( string $modelName ) : void Set the name of the Model to be used by this View
setDoTask ( string $task )
setLayout ( string $layout ) : string Sets the layout name to use
setModel ( string $modelName, Model &$model ) : void Pushes a named model to the View
setPostRender ( boolean $value ) : void Sets the post-render flag
setPreRender ( boolean $value ) : void Sets the pre-render flag
setTask ( string $task )
startSection ( string $section, string $content = '' ) : void Start injecting content into a section.
stopSection ( boolean $overwrite = false ) : string Stop injecting content into a section.
yieldContent ( string $section, string $default = '' ) : string Get the string contents of a section.
yieldSection ( ) : string Stop injecting content into a section and return its contents.

Protected Methods

Method Description
addTemplatePath ( mixed $path ) : void Adds to the search path for templates and resources.
evaluateTemplate ( array &$forceParams ) : string Evaluates the template described in the _tempFilePath property
extendSection ( string $section, string $content ) : void Append content to a given section.
getEngine ( string $path ) : FOF30\View\Engine\EngineInterface Get the appropriate view engine for the given view template path.
getExtension ( string $path ) : string Get the extension used by the view file.
handleViewException ( Exception $e, integer $obLevel ) : void Handle a view exception.
postRender ( ) : void Runs after rendering the view template, echoing HTML to put after the view template's generated HTML
preRender ( ) : void Runs before rendering the view template, echoing HTML to put before the view template's generated HTML
setTemplatePath ( mixed $path ) : void Sets an entire array of search paths for templates or resources.
triggerEvent ( string $event, array $arguments = [] ) : boolean Triggers an object-specific event. The event runs both locally –if a suitable method exists– and through the Joomla! plugin system. A true/false return value is expected. The first false return cancels the event.

Private Methods

Method Description
includeTemplateFile ( array &$forceParams ) : void This method makes sure the current scope isn't polluted with variables when including a view template

Method Details

__construct() public method

The $config array can contain the following overrides: name string The name of the view (defaults to the view class name) template_path string The path of the layout directory layout string The layout for displaying the view viewFinder ViewTemplateFinder The object used to locate view templates in the filesystem viewEngineMap array Maps view template extensions to view engine classes
public __construct ( Container $container, array $config = [] ) : View
$container FOF30\Container\Container The container we belong to
$config array The configuration overrides for the view
return View

__get() public method

Magic get method. Handles magic properties: $this->input mapped to $this->container->input
public __get ( string $name ) : mixed | null
$name string The property to fetch
return mixed | null

addCssFile() public method

Add a CSS file to the page generated by the CMS
public addCssFile ( string $uri, string $version = null, string $type = 'text/css', string $media = null, array $attribs = [] )
$uri string A path definition understood by parsePath, e.g. media://com_example/css/foo.css
$version string (optional) Version string to be added to the URL
$type string MIME type of the stylesheeet
$media string Media target definition of the style sheet, e.g. "screen"
$attribs array Array of attributes

addCssInline() public method

Adds an inline stylesheet (inline CSS) to the page header
public addCssInline ( string $css, string $type = 'text/css' )
$css string The stylesheet content to add
$type string The MIME type of the script

addJavascriptFile() public method

There are three combinations of defer and async (see http://www.w3schools.com/tags/att_script_defer.asp): * $defer false, $async true: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) * $defer true, $async false: The script is executed when the page has finished parsing. * $defer false, $async false. (default) The script is loaded and executed immediately. When it finishes loading the browser continues parsing the rest of the page. When you are using $defer = true there is no guarantee about the load order of the scripts. Whichever script loads first will be executed first. The order they appear on the page is completely irrelevant.
public addJavascriptFile ( string $uri, string $version = null, string $type = 'text/javascript', boolean $defer = false, boolean $async = false )
$uri string A path definition understood by parsePath, e.g. media://com_example/js/foo.js
$version string (optional) Version string to be added to the URL
$type string MIME type of the script
$defer boolean Adds the defer attribute, see above
$async boolean Adds the async attribute, see above

addJavascriptInline() public method

Adds an inline JavaScript script to the page header
public addJavascriptInline ( string $script, string $type = 'text/javascript' )
$script string The script content to add
$type string The MIME type of the script

addLess() public method

This method has integrated cache support. The compiled LESS files will be written to the media/lib_fof/compiled directory of your site. If the file cannot be written we will use the $cssUri, if specified
public addLess ( string $uri, string $cssUri, string $version = null, string $type = 'text/css', string $media = null, array $attribs = [] )
$uri string A path definition understood by parsePath pointing to the source LESS file, e.g. media://com_example/less/foo.less
$cssUri string A path definition understood by parsePath pointing to a precompiled CSS file, used when we can't write the generated file to the output directory, e.g. media://com_example/css/foo.css
$version string (optional) Version string to be added to the URL
$type string MIME type of the stylesheeet
$media string Media target definition of the style sheet, e.g. "screen"
$attribs array Array of attributes

addTemplatePath() protected method

Adds to the search path for templates and resources.
protected addTemplatePath ( mixed $path ) : void
$path mixed The directory or stream, or an array of either, to search.
return void

alias() public method

Add an alias for a view template.
public alias ( string $viewTemplate, string $alias ) : void
$viewTemplate string Existing view template, in the format componentPart://componentName/viewName/layoutName
$alias string The alias of the view template (any string will do)
return void

appendSection() public method

Stop injecting content into a section and append it.
public appendSection ( ) : string
return string

decrementRender() public method

Decrement the rendering counter.
public decrementRender ( ) : void
return void

display() public method

Instead of loadTemplate is uses loadAnyTemplate.
public display ( string $tpl = null ) : boolean
$tpl string The name of the template file to parse
return boolean True on success

doneRendering() public method

Check if there are no active render operations.
public doneRendering ( ) : boolean
return boolean

escape() public method

Escapes a value for output in a view script.
public escape ( mixed $var ) : mixed
$var mixed The output to escape.
return mixed The escaped value.

evaluateTemplate() protected method

Evaluates the template described in the _tempFilePath property
protected evaluateTemplate ( array &$forceParams ) : string
$forceParams array Forced parameters
return string

extendSection() protected method

Append content to a given section.
protected extendSection ( string $section, string $content ) : void
$section string
$content string
return void

flushSections() public method

Flush all of the section contents.
public flushSections ( ) : void
return void

flushSectionsIfDoneRendering() public method

Flush all of the section contents if done rendering.
public flushSectionsIfDoneRendering ( ) : void
return void

get() public method

Method to get data from a registered model or a property of the view
public get ( string $property, string $default = null, string $modelName = null ) : mixed
$property string The name of the method to call on the Model or the property to get
$default string The default value [optional]
$modelName string The name of the Model to reference [optional]
return mixed The return value of the method

getContainer() public method

Returns a reference to the container attached to this View
public getContainer ( ) : Container
return FOF30\Container\Container

getDoTask() public method

public getDoTask ( )

getEngine() protected method

Get the appropriate view engine for the given view template path.
protected getEngine ( string $path ) : FOF30\View\Engine\EngineInterface
$path string The path of the view template
return FOF30\View\Engine\EngineInterface

getExtension() protected method

Get the extension used by the view file.
protected getExtension ( string $path ) : string
$path string
return string

getLayout() public method

Get the layout.
public getLayout ( ) : string
return string The layout name

getLayoutTemplate() public method

Get the layout template.
public getLayoutTemplate ( ) : string
return string The layout template name

getModel() public method

Returns a named Model object
public getModel ( string $name = null ) : Model
$name string The Model name. If null we'll use the modelName variable or, if it's empty, the same name as the Controller
return FOF30\Model\Model The instance of the Model known to this Controller

getName() public method

The model name by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor
public getName ( ) : string
return string The name of the model

getTask() public method

public getTask ( )

handleViewException() protected method

Handle a view exception.
protected handleViewException ( Exception $e, integer $obLevel ) : void
$e Exception The exception to handle
$obLevel integer The target output buffering level
return void

incrementRender() public method

Increment the rendering counter.
public incrementRender ( ) : void
return void

loadAnyTemplate() public method

Loads a template given any path. The path is in the format componentPart://componentName/viewName/layoutName, for example site:com_example/items/default admin:com_example/items/default_subtemplate auto:com_example/things/chair any:com_example/invoices/printpreview
public loadAnyTemplate ( string $uri = '', array $forceParams = [], callable $callback = null ) : string
$uri string The template path
$forceParams array A hash array of variables to be extracted in the local scope of the template file
$callback callable A method to post-process the evaluated view template
return string The output of the template

loadHelper() public method

Load a helper file
Deprecation: 3.0 Just use the class in your code. That's what the autoloader is for.
public loadHelper ( string $helperClass = null ) : void
$helperClass string The last part of the name of the helper class.
return void

loadTemplate() public method

Our function uses loadAnyTemplate to provide smarter view template loading.
public loadTemplate ( string $tpl = null, boolean $strict = false ) : mixed
$tpl string The name of the template file to parse
$strict boolean Should we use strict naming, i.e. force a non-empty $tpl?
return mixed A string if successful, otherwise an Exception

populateFromModel() public method

This method is called by the Renderer when an XML form includes a view template. The $model variable contains the Model object instance used by the form. You can override this method to populate your View class with data from that model.
public populateFromModel ( Model $model )
$model FOF30\Model\Model The model object passed from the XML form renderer

postRender() protected method

Runs after rendering the view template, echoing HTML to put after the view template's generated HTML
protected postRender ( ) : void
return void

preRender() protected method

Runs before rendering the view template, echoing HTML to put before the view template's generated HTML
protected preRender ( ) : void
return void

renderEach() public method

Go through a data array and render a subtemplate against each record (think master-detail views). This is accessible through Blade templates as @each
public renderEach ( string $viewTemplate, array $data, string $eachItemName, string $empty = 'raw|' ) : string
$viewTemplate string The view template to use for each subitem, format componentPart://componentName/viewName/layoutName
$data array The array of data you want to render. It can be a DataModel\Collection, array, ...
$eachItemName string How to call each item in the loaded subtemplate (passed through $forceParams)
$empty string What to display if the array is empty
return string

setDefaultModel() public method

Pushes the default Model to the View
public setDefaultModel ( Model &$model )
$model FOF30\Model\Model The model to push

setDefaultModelName() public method

Set the name of the Model to be used by this View
public setDefaultModelName ( string $modelName ) : void
$modelName string The name of the Model
return void

setDoTask() public method

public setDoTask ( string $task )
$task string

setLayout() public method

Sets the layout name to use
public setLayout ( string $layout ) : string
$layout string The layout name or a string in format