Kotchasan

View extends KBase
in package

This class provides basic functionalities for views.

It is responsible for rendering HTML templates, managing CSS and JavaScript files, and handling headers.

Tags
see
https://www.kotchasan.com/

Table of Contents

$afterContents  : array<string|int, mixed>
Array to store the contents of the website to be replaced after rendering.
$cfg  : object
Config class instance.
$contents  : array<string|int, mixed>
Array to store the contents of the website.
$headers  : array<string|int, mixed>
Array to store the headers.
$metas  : array<string|int, mixed>
Array to store meta tags.
$request  : Request
Server request class instance.
$scripts  : array<string|int, mixed>
Array to store JavaScript code to be inserted in the head section.
addCSS()  : mixed
Adds a CSS file to the header.
addJavascript()  : mixed
Adds a JavaScript file to the header.
addScript()  : mixed
Adds JavaScript code to be inserted in the head section before closing the head tag.
array_value()  : mixed
Get the value from an array based on a given key.
back()  : string
Replaces the query string with data from the GET request for forwarding to the next URL.
create()  : static
Creates an instance of the View class.
object_value()  : mixed
Get the value from an object based on a given key.
output()  : mixed
Outputs the content and headers as specified.
renderHTML()  : string
Renders the content as HTML.
setContents()  : mixed
Sets the content in $contents.
setContentsAfter()  : mixed
Sets the content in $contents after rendering.
setHeaders()  : mixed
Sets headers for the document.
setMetas()  : mixed
Adds meta tags to the HTML head.

Properties

$afterContents

Array to store the contents of the website to be replaced after rendering.

protected array<string|int, mixed> $afterContents = []

$cfg

Config class instance.

protected static object $cfg

$contents

Array to store the contents of the website.

protected array<string|int, mixed> $contents = []

$headers

Array to store the headers.

protected array<string|int, mixed> $headers = []

$metas

Array to store meta tags.

protected array<string|int, mixed> $metas = []

$request

Server request class instance.

protected static Request $request

$scripts

Array to store JavaScript code to be inserted in the head section.

protected array<string|int, mixed> $scripts = []

Methods

addCSS()

Adds a CSS file to the header.

public addCSS(string $url) : mixed
Parameters
$url : string

The URL of the CSS file.

Return values
mixed

addJavascript()

Adds a JavaScript file to the header.

public addJavascript(string $url) : mixed
Parameters
$url : string

The URL of the JavaScript file.

Return values
mixed

addScript()

Adds JavaScript code to be inserted in the head section before closing the head tag.

public addScript(string $script) : mixed
Parameters
$script : string

The JavaScript code.

Return values
mixed

array_value()

Get the value from an array based on a given key.

public static array_value(array<string|int, mixed> $array, string $key[, mixed $default = '' ]) : mixed

If the key doesn't exist, return the default value.

Parameters
$array : array<string|int, mixed>

The array to search in.

$key : string

The key to retrieve the value from.

$default : mixed = ''

The default value to return if the key doesn't exist.

Return values
mixed

The value from the array or the default value.

back()

Replaces the query string with data from the GET request for forwarding to the next URL.

public static back(array<string|int, mixed>|string $f) : string

The function takes either an array (returned from preg_replace) or a string. Returns the new query string with the 'id=0' removed.

Parameters
$f : array<string|int, mixed>|string

The value from the variable $f used to create the query string.

Tags
assert

(array(2 => 'module=retmodule&id=0')) [==] "http://localhost/?module=retmodule&page=1&sort=id" [[$_SERVER['QUERY_STRING'] = '_module=test&1234&_page=1&_sort=id&action=login&id=1']]

assert

('module=retmodule&5678') [==] "http://localhost/?module=retmodule&page=1&sort=id&id=1&5678"

Return values
string

The new query string.

create()

Creates an instance of the View class.

public static create() : static
Return values
static

object_value()

Get the value from an object based on a given key.

public static object_value(object $source, string $key[, mixed $default = '' ]) : mixed

If the key doesn't exist, return the default value.

Parameters
$source : object

The object to retrieve the value from.

$key : string

The key to retrieve the value from.

$default : mixed = ''

The default value to return if the key doesn't exist.

Return values
mixed

The value from the object or the default value.

output()

Outputs the content and headers as specified.

public output(string $content) : mixed
Parameters
$content : string

The content to be output.

Return values
mixed

renderHTML()

Renders the content as HTML.

public renderHTML([string|null $template = null ]) : string
Parameters
$template : string|null = null

The HTML template to be used. If not specified (null), 'index.html' will be used.

Return values
string

The rendered HTML content.

setContents()

Sets the content in $contents.

public setContents(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

An array of names to be used in the template (e.g., array(key1 => val1, key2 => val2)).

Return values
mixed

setContentsAfter()

Sets the content in $contents after rendering.

public setContentsAfter(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

An array of names to be used in the template (e.g., array(key1 => val1, key2 => val2)).

Return values
mixed

setHeaders()

Sets headers for the document.

public setHeaders(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

An array of headers (e.g., array(key1 => val1, key2 => val2)).

Return values
mixed

setMetas()

Adds meta tags to the HTML head.

public setMetas(array<string|int, mixed> $array) : mixed
Parameters
$array : array<string|int, mixed>

An array of meta tags (e.g., array(key1 => val1, key2 => val2)).

Return values
mixed

Search results