\Piko\View

Base application view.

Constants summary

Name Description
public POS_END End of body position.
public POS_HEAD Head position.

Properties summary

Name Description
public $charset The charset encoding used in the view.
public $css The registered CSS code blocks.
public $cssFiles The registered CSS files.
public $endBody Parts of the end of the body.
public $extension View filename extension
public $head Parts of the head.
public $js The registered JS code blocks
public $jsFiles The registered JS files.
public $params View parameters.
public $paths Directories where to find view files.
public $themeMap Theme map configuration. A key paired array where …
public $title The page title

Inherited Properties

Name Description
public $behaviors Behaviors container.
protected $eventDispatcher  
protected $listenerProvider  

Methods summary

Name Description
public __construct Constructor
public escape Escape HTML special characters.
public registerCSS Register css code.
public registerCSSFile Register a stylesheet url.
public registerJs Register a script.
public registerJsFile Register a script url.
public render Render the view.
protected applyTheme Try to find an override of the file in a theme.
protected endBody Assemble html in the end of the body position.
protected findFile Retrieve a view file.
protected head Assemble html in the head position.

Inherited Methods

Name Description
public __call Magic method to call a behavior.
public attachBehavior Attach a behavior to the class instance.
public detachBehavior Detach a behavior.
public on  
public trigger Trigger an event that may be listen by event liste…

public $POS_END

End of body position.

public $POS_HEAD

Head position.


Properties

public $charset : string

The charset encoding used in the view.

public $css : string[]

The registered CSS code blocks.

see \Piko\View::registerCss()

public $cssFiles : string[]

The registered CSS files.

see \Piko\View::registerCssFile()

public $endBody : string[]

Parts of the end of the body.

public $extension : string

View filename extension

public $head : string[]

Parts of the head.

public $js : string[][]

The registered JS code blocks

see \Piko\View::registerJs()

public $jsFiles : string[][]

The registered JS files.

see \Piko\View::registerJsFile()

public $params : array

View parameters.

public $paths : string[]

Directories where to find view files.

public $themeMap : array<string,string|string[]>

Theme map configuration. A key paired array where each key represents a path to override and the value, the mapped path. The value could be either a string or an array of path and in this case, it may be possibe to use child themes. Configuration example :

...
'view' => [
    'class' => 'piko\View',
    'themeMap' => [
        '@app/modules/site/views' => [
            '@app/themes/child-theme',
            '@app/themes/parent-theme',
        ],
        '@app/modules/admin/views' => '@app/themes/piko/admin',
    ],
],

public $title : string

The page title


Methods

public __construct(): mixed

public  __construct(array&lt;string,mixed&gt;  $config = []): mixed

Parameters

$config (default: []):

Return:

mixed


public escape(): string

public  escape(string  $string): string

Escape HTML special characters.

Parameters

$string : Dirty html.

Return:

string Clean html.


public registerCSS(): void

public  registerCSS(string  $css, string  $key = null): void

Register css code.

Parameters

$css : The css code.

$key (default: null): An optional identifier


public registerCSSFile(): void

public  registerCSSFile(string  $url): void

Register a stylesheet url.

Parameters

$url : The stylesheet url.


public registerJs(): void

public  registerJs(string  $js, int  $position = self::POS_END, string  $key = null): void

Register a script.

Parameters

$js : The script code.

$position (default: self::POS_END): The view position where to insert the script (default at the end of the body).

$key (default: null): An optional identifier


public registerJsFile(): void

public  registerJsFile(string  $url, int  $position = self::POS_END, string  $key = null): void

Register a script url.

Parameters

$url : The script url.

$position (default: self::POS_END): The view position where to insert the script (default at the end of the body).

$key (default: null): An optional identifier


public render(): string

public  render(string  $file, array  $model = []): string

Render the view.

Parameters

$file : The view file name.

$model (default: []): An array of data (name-value pairs) to transmit to the view file.

Return:

string The view output.


protected applyTheme(): string

protected  applyTheme(string  $path): string

Try to find an override of the file in a theme.

Parameters

$path : The file path

Return:

string The overriden or not file path


protected endBody(): string

protected  endBody(): string

Assemble html in the end of the body position.

Return:

string The end of the body html.


protected findFile(): string

protected  findFile(string  $viewName): string

Retrieve a view file.

Parameters

$viewName : The view name (without extension).

throws \RuntimeExceptionif view file not found.

Return:

string The path of the view file.


protected head(): string

protected  head(): string

Assemble html in the head position.

Return:

string The head html.