Properties

$baseTemplate

$baseTemplate : string

Type

string — The base template to use for the view.

$ajaxTemplate

$ajaxTemplate : string

Type

string — The base template to use for the view.

$errorDir

$errorDir : string

Type

string — The relative path to the directory which holds server error responses.

$activeIndex

$activeIndex : integer

Type

integer — Standard scrape for `$indexes`.

$view

$view : array

Type

array — The data to be injected into the $baseTemplate template when rendered.

$lastCallType

$lastCallType : string

Type

string — Flips between script and style.

$indexes

$indexes : array

Type

array — How should it be scraped.

Methods

__toString()

__toString() : string

If the view is called in a twig template we want to just return an empty string.

Returns

string

get()

get(string  $k) : mixed

Get a variable in the view template variable.

Parameters

string $k

The variable name.

Returns

mixed

set()

set(string  $k, mixed  $v) : void

Set a variable in the view template variable.

Parameters

string $k

The variable name.

mixed $v

The variables value.

setBaseTemplate()

setBaseTemplate(string  $template) : void

Override the default body template for the View.

Parameters

string $template

The template to use.

setAjaxTemplate()

setAjaxTemplate(string  $template) : void

Override the default body template for the Ajax View.

Parameters

string $template

The template to use.

setViewVariable()

setViewVariable(string  $k, mixed  $v) : void

Set a variable in the view template variable.

Parameters

string $k

The variable name.

mixed $v

The variables value.

getViewVariable()

getViewVariable(string  $k) : mixed

Get a variable in the view template variable.

Parameters

string $k

The variable name.

Returns

mixed

json()

json(null|mixed  $data = null, integer  $code = 200) : void

Specify that the output of this view should be JSON. If `$data` is provided the response will be sent immeditatly and the application will exit.

Parameters

null|mixed $data

The response to JSON encode and return to the client. If $data is a string, it is assumed that it has already been JSON encoded.

integer $code

The HTTP response code to be returned to the client.

isJson()

isJson() : boolean

Return whether the View is JSON.

Returns

boolean

header()

header() : string

Get the markup set for the View header, from $this->header.

Returns

string —

Return $this->header

getHeader()

getHeader() : string

Get the markup of the header, if its been set in `header` that will returned otherwise `$this->header()` will be called.

Returns

string

setHeader()

setHeader(string  $html) : void

Set the markup for the view header, in $this->header.

Parameters

string $html

the markup

footer()

footer() : string

Get the markup set for the view footer.

Returns

string —

Returns $this->footer

getFooter()

getFooter() : string

Get the markup of the footer, if its been set in `footer` that will returned otherwise `$this->footer()` will be called.

Returns

string

setFooter()

setFooter(string  $html) : void

Set the markup for the view footer.

Parameters

string $html

The markup to put in $this->footer

lang()

lang(string  $lang = null) : void

Set the lang of the page.

Parameters

string $lang

The language to set the page as.

charset()

charset(string  $charset = null) : void

Set the charset of the page.

Parameters

string $charset

the charset the page should use

headExtra()

headExtra(string  $extra = null) : void

Set extra elements in the header as a string.

Parameters

string $extra

the markup to put in the head of the page

robots()

robots() : \Disco\classes\string.

Return the robots index type.

Returns

\Disco\classes\string.

schema()

schema(string|array  $keyOrData, mixed|null  $value = null) 

Set information to be used in schema.org json-ld data that will be set in the header of the view.

Parameters

string|array $keyOrData

Either a key to set in the schema, or an array to merge with the current schema.

mixed|null $value

A value to set in the schema or null if $keyOrData was an array.

getSchema()

getSchema() : array

Get the current schema data.

Returns

array —

The schema data.

setSchema()

setSchema(array  $schema) 

Set the schema.org markup to be set in the header, overwriting any existing data set prior.

Parameters

array $schema

The schema data.

printPage()

printPage() : void

If the view is AJAX render and echo the tempalte `$this->ajaxTemplate` otherwise render the template `$this->baseTemplate`.

ajax()

ajax(boolean  $bool = true) : void

Set that the view is returning a response to a client via an AJAX request.

Parameters

boolean $bool

Whether were responding to an AJAX request.

isAjax()

isAjax() : boolean

Is the request AJAX?

Returns

boolean

title()

title(null|string  $t = null) : string|void

Set/Get the title of the view.

Parameters

null|string $t

The title of the page.

Returns

string|void

desc()

desc(null|string  $d = null) : string|void

Set/Get the description of the view.

Parameters

null|string $d

The description of the page.

Returns

string|void

html()

html(string  $h) 

Add a snippet of html to the view.

Parameters

string $h

a string to put into the view

body()

body(null|string  $b = null) : string|void

Get/Set the body of the request.

Parameters

null|string $b

The body.

Returns

string|void

favIcon()

favIcon(null|string  $v = null) : string|void

Set/Get the favicon to be used by the page.

Parameters

null|string $v

the path to the favicon

Returns

string|void

url()

url(string  $p) : string

Create FQDN link.

Parameters

string $p

The path of the resource.

Returns

string —

The FQDN.

localUrl()

localUrl(string  $p) : string

Create FQDN link.

Parameters

string $p

The path of the resource.

Returns

string —

The FQDN.

appendLastMod()

appendLastMod(string  $path, string  $var = 'c') : string

Append the last modified time to a resource path in a GET variable (default is `c`). This can be useful if your caching assets via `.htaccess` rules and you dont want to have to rename them manually after every change.

Parameters

string $path

The path to the resource as used in the front end.

string $var

The GET variable name to store the last modified time in.

Returns

string —

The path with the last modified time appended.

prop()

prop(string  $k, string  $v) : void

Set a property on a script or style.

Parameters

string $k

The key name.

string $v

The value.

script()

script(string  $s) 

Add a Javascript snippet to the page.

Parameters

string $s

A block of javascript code.

scriptSrc()

scriptSrc(string  $path, boolean  $appendLastMod = false) : self

Add a Javascript file to the page by URL.

Parameters

string $path

A URL path to a javascript file.

boolean $appendLastMod

Whether to append the last modified time to the resource path.

Returns

self

headScriptSrc()

headScriptSrc(string  $path, boolean  $appendLastMod = false) : self

Add a Javascript file to the page head by URL.

Parameters

string $path

A URL path to a javascript file.

boolean $appendLastMod

Whether to append the last modified time to the resource path.

Returns

self

style()

style(string  $s) : void

Add a css style to the page.

Parameters

string $s

The css style that should be applied to the page.

styleSrc()

styleSrc(string  $path, boolean  $appendLastMod = false) : self

Add a CSS file to the page by URL.

Parameters

string $path

A url path to a CSS file.

boolean $appendLastMod

Whether to append the last modified time to the resource path.

Returns

self

bodyClass()

bodyClass(  $class) 

Add a body class.

Parameters

$class

bodyClasses()

bodyClasses() : string

Get the class of the body.

Returns

string

index()

index() 

Set the index type to index,follow , $this->activeIndex=0.

noIndex()

noIndex() 

Set the index type to noindex,nofollow , $this->activeIndex=1.

indexNoFollow()

indexNoFollow() 

Set the index type to index,nofollow, $this->activeIndex=2.

noIndexFollow()

noIndexFollow() 

Set the index type to noindex,follow, $this->activeIndex=3.

printStyleSrcs()

printStyleSrcs() : string

Complile the style(css) sources to html `<link>` elements.

Returns

string —

The compliled elements.

printStyles()

printStyles() : null|string

Create a single `<style><style/>` element containing any added styles.

Returns

null|string

printHeadScriptSrcs()

printHeadScriptSrcs() : string

Complile the head script(js) sources to html `<script>` elements.

Returns

string —

The compliled elements.

printScriptSrcs()

printScriptSrcs() : string

Complile the script(js) sources to html `<script>` elements.

Returns

string —

The compliled elements.

printScripts()

printScripts() : null|string

Create a single `<script><script/>` element containing any added scripts.

Returns

null|string

abort()

abort(boolean|string|\Closure  $action = false) 

Serve a 404, executing an optional closure or template.

Parameters

boolean|string|\Closure $action

Optional template or Closure function.

error()

error(integer  $code = 500, boolean|string|\Closure  $action = false) 

Serve an error page, defined by a template or an error file, stored in $this->errorDir.

Parameters

integer $code

The HTTP Error code.

boolean|string|\Closure $action

Optional template or Closure function.

redirect()

redirect(string  $url) : void

Redirect the request to another URL.

Parameters

string $url

The URL to redirect to.

httpHeader()

httpHeader(string  $h) : void

Add a HTTP header to the response.

Parameters

string $h

The HTTP header to add.

serve()

serve(integer  $code = 200, boolean|string|\Closure  $action = false) : void

Serve a specified http response code page by either executing a template or the passed \Closure $fun function, or loading the \Closure function from the file $this->errorDir . $code.php and executing it or by a default message set by the function.

Parameters

integer $code

The http repsonse code sent to the client from the server.

boolean|string|\Closure $action

A template or closure to execute when $code != 200.

addSchemaToHeadExtra()

addSchemaToHeadExtra() 

When print page is called if there is schema information to add to the head of the page this will add it inside a script tag with the type set to `application/ld+json`. This will also check and see if the key `@context` has been set, if not it will be set to `http://schema.org`.

printScriptsFromSource()

printScriptsFromSource(array  $src) : string

Complile the script(js) sources to html `<script>` elements.

Parameters

array $src

The js sources.

Returns

string —

The compliled elements.