ViewMaker

View Maker Trait Adds view based methods to a class

 trait System\Traits\ViewMaker

Properties

public $layout : string

Layout to use for the view.

public $suppressLayout : bool

Prevents the use of a layout.

public $vars : array

A list of variables to pass to the page.

protected $layoutPath : string

Specifies a path to the layout directory.

protected $viewPath : string | array

Specifies a path to the views directory.

Methods

public addViewPath (string | array $path) : void

Prepends a path on the available view path locations.

Parameters
Property Description
$path
string | array
Returns
void

public getViewPath (string $fileName, $viewPaths = null) : string

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.

If the fileName cannot be found it will be returned unmodified.

Parameters
Property Description
$fileName
string
$viewPaths
mixed
Returns
string

public getViewPaths () : array

Returns the active view path locations.

Returns
array

public guessViewPath (string $suffix = "", boolean $isPublic = false) : string | null

Guess the package path for the called class.

Parameters
Property Description
$suffix
string

An extra path to attach to the end

$isPublic
boolean

Returns public path instead of an absolute one

Returns
string | null

public guessViewPathFrom (string $class, string $suffix = "", boolean $isPublic = false) : string | null

Guess the package path from a specified class.

Parameters
Property Description
$class
string

Class to guess path from.

$suffix
string

An extra path to attach to the end

$isPublic
boolean

Returns public path instead of an absolute one

Returns
string | null

public makeFileContents (string $filePath, array $extraParams = []) : string

Includes a file path using output buffering, making the provided vars available.

Parameters
Property Description
$filePath
string
$extraParams
array
Returns
string

public makeLayout ($name = null, array $params = [], boolean $throwException = true) : string | bool

Render a layout, defaulting to the layout propery specified on the class

Parameters
Property Description
$name
mixed
$params
array
$throwException
boolean
Returns
string | bool

The layout contents, or false.

public makeLayoutPartial (string $partial, array $params = []) : string

Renders a layout partial

Parameters
Property Description
$partial
string
$params
array
Returns
string

public makePartial (string $partial, array $params = [], boolean $throwException = true) : mixed

Render a partial file contents located in the views folder.

Parameters
Property Description
$partial
string
$params
array
$throwException
boolean
Returns
mixed

Partial contents or false if not throwing an exception.

public makeView (string $view) : string

Loads the specified view. Applies the layout if one is set.

The view file must have the .php extension (or ".htm" for historical reasons) and be located in the views directory

Parameters
Property Description
$view
string
Returns
string

public makeViewContent (string $contents, $layout = null) : string

Renders supplied contents inside a layout.

Parameters
Property Description
$contents
string
$layout
mixed
Returns
string

protected handleViewException (Throwable $e, integer $obLevel) : void

Handle a view exception.

Parameters
Property Description
$e
Throwable
$obLevel
integer
Returns
void
Copyright © 2024 Winter CMS