System\Traits\ViewMaker

ViewMaker Trait adds view based methods to a class

Public properties

public array $vars

vars is a list of variables to pass to the page

public string $layout

layout to use for the view

public bool $suppressLayout

suppressLayout prevents the use of a layout

Protected properties

protected string|array $viewPath

viewPath specifies a path to the views directory

protected string $layoutPath

layoutPath specifies a path to the layout directory

Public methods

public void addViewPath(string|array $path)

addViewPath prepends a path on the available view path locations

Parameters
  • string|array $path

public string getViewPath(string $fileName, mixed $viewPath=NULL)

getViewPath locates a file based on its definition. The file name can be prefixed with a symbol (~|$) to return in context of the application or plugin base path, otherwise it will be returned in context of this object view path.

Parameters
  • string $fileName - File to load.
  • mixed $viewPath - Explicitly define a view path.

public array getViewPaths()

getViewPaths returns the active view path locations

public string guessViewPath(string $suffix='', bool $isPublic=false)

guessViewPath guesses the package path for the called class

Parameters
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

public string guessViewPathFrom(string $class, string $suffix='', bool $isPublic=false)

guessViewPathFrom guesses the package path from a specified class

Parameters
  • string $class - Class to guess path from.
  • string $suffix - An extra path to attach to the end
  • bool $isPublic - Returns public path instead of an absolute one

public string makeFileContents(string $filePath, array $extraParams=array())

makeFileContents includes a file path using output buffering

Parameters
  • string $filePath - Absolute path to the view file.
  • array $extraParams - Parameters that should be available to the view.

public mixed makeLayout(string $name=NULL, array $params=array(), bool $throwException=true)

makeLayout renders a layout

Parameters
  • string $name - Specifies the layout name. If this parameter is omitted, the $layout property will be used.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the layout is not found

public string makeLayoutPartial(string $partial, array $params=array())

makeLayoutPartial renders a layout partial

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.

public mixed makePartial(string $partial, array $params=array(), bool $throwException=true)

makePartial renders a partial file contents located in the views folder

Parameters
  • string $partial - The view to load.
  • array $params - Parameter variables to pass to the view.
  • bool $throwException - Throw an exception if the partial is not found.

public string makeView(string $view)

makeView loads a view with the name specified. Applies layout if its name is provided by the parent object. The view file must be situated in the views directory, and has the extension "htm"

Parameters
  • string $view - Specifies the view name, without extension. Eg: "index".

public string makeViewContent(string $contents, string $layout=NULL)

makeViewContent renders supplied contents inside a layout

Parameters
  • string $contents - The inner contents as a string.
  • string $layout - Specifies the layout name.

Protected methods

protected void handleViewException($e, $obLevel)

handleViewException handles a view exception

Parameters
  • $e
  • $obLevel