Show:

Q_Response Class

Module: Q

This class deals with returning a response

Item Index

Methods

Properties

Methods

addError

(
  • $exception
)
static

Adds an error to the response

Parameters:

  • $exception Q_Exception | Array

    Either a Q_Exception or an array of them

addHtmlCssClass

(
  • $className
)
static

Call this method to add a css class to the HTML element in the layout

Parameters:

  • $className String

addScript

(
  • $src
  • [$slotName=null]
  • [$type='text/javascript']
)
Boolean static

Adds a script reference to the response

Parameters:

  • $src String
  • [$slotName=null] String optional
  • [$type='text/javascript'] String optional

Returns:

Boolean:

returns false if script was already added, else returns true

addScriptLine

(
  • $line
  • [$replace=array()]
  • [$slotName=null]
)
static

Adds a line of script to be echoed in a layout

Parameters:

  • $line String

    The line of script

  • [$replace=array()] Array optional

    Keys in this array are globally replaced in the $line with the json_encoded values, before the line is added.

  • [$slotName=null] Array optional

    A way to override the slot name. Pass "" here to have the script lines be returned first by Q_Response::scriptLines. The other special value, "Q", is intended for internal use.

addStylesheet

(
  • $href
  • [$slotName=null]
  • [$media='screen,print']
  • [$type='text/css']
)
Boolean static

Adds a stylesheet

Parameters:

  • $href String
  • [$slotName=null] String optional
  • [$media='screen,print'] String optional
  • [$type='text/css'] String optional

Returns:

Boolean:

returns false if a stylesheet with exactly the same parameters has already been added, else true.

addTemplate

(
  • $name
  • [$slotName=null]
  • [$type="handlebars"]
  • [$params=array()]
)
Boolean static

Adds inline template to the response

Parameters:

  • $name String

    The location of the template file relative to the "views" folder

  • [$slotName=null] Array optional

    A way to override the slot name. Pass "" here to have the script lines be returned first by Q_Response::scriptLines. The other special value, "Q", is intended for internal use.

  • [$type="handlebars"] String optional

    The type of the template, such as "php" or "handlebars".

  • [$params=array()] Array optional

    Optional array of parameters to pass to PHP

Returns:

Boolean:

returns false if template was already added, else returns true

clearCookie

(
  • $name
  • [$path=false]
)
String static

Parameters:

  • $name String
  • [$path=false] String optional

Returns:

String:

clearSlot

(
  • $slotName
)
static

Clears a slot, so the next call to Q_Response::fillSlot would fill it again

Parameters:

  • $slotName String

    The name of the slot.

faviconUrl

(
  • [$new_url=null]
)
String static

Gets/sets the favicon url

Parameters:

  • [$new_url=null] String optional

Returns:

String:

fillSlot

(
  • $slotName
  • [$default_slotName=null]
  • [$prefix=null]
)
String | Null static

Gets the current content of a slot, if any. If slot content is null, then raises an event to try to fill the slot. If it is filled, returns the content. Otherwise, returns null.

Parameters:

  • $slotName String | Array

    The name of the slot.

  • [$default_slotName=null] Boolean optional

    If the slot named in $slotName returns null, the handler corresponding to the default slot will be called, passing it the requested slot's name in the 'slotName' parameter, and its value will be returned instead. Note: this does not fill the slot named $default_slotName! That is to say, the computed value is not saved, so that the slot's handler is called again if it is ever consulted again.

  • [$prefix=null] String optional

    Sets a prefix for the HTML ids of all the elements in the slot.

Returns:

String | Null:

getAllSlots

() Array static

Gets all the slots that have been set

Returns:

Array:

getErrors

() Array static

Returns all the errors added so far to the response.

Returns:

Array:

getNotices

() Array static

Returns all the notices added so far to the response.

Returns:

Array:

getRemovedNotices

() Array static

Returns all the notices removed so far during this request

Returns:

Array:

getRequestedSlots

() Array static

Gets all the requested slots using Q_Request::slotNames()

Returns:

Array:

getSlot

(
  • $slotName
)
String | Null static

Gets the content of a slot, or null if it wasn't filled

Parameters:

  • $slotName String

    The name of the slot.

Returns:

String | Null:

getToolOptions

(
  • toolName
)
Array static

Get all the options set for a tool so far

Parameters:

  • toolName String

    Optional name of the tool that is being rendered

Returns:

Array:

The options for the tool currently being rendered

htmlAttributes

() String static

Returns the string containing all the html attributes

Returns:

String:

isBuffered

(
  • [$new_value=null]
)
Boolean | String static

Gets or sets whether the response is buffered.

Parameters:

  • [$new_value=null] Boolean | String optional

    If not present, just returns the current value of this setting. If true or false, sets the setting to this value, and returns the setting's old value.

Returns:

Boolean | String:

language

(
  • [$newLanguage]
)
String static

Used to get or set the language (two-letter lowercase ISO code) of the output page. Defaults to "en". It is used in htmlAttributes method.

Parameters:

  • [$newLanguage] String optional

    Set a new code here to change the language

Returns:

String:

layoutView

(
  • $newView
)
String static

Get or set the layout view that should be used in the response

Parameters:

  • $newView String

    optionally set the new view, or unset it by passing false

Returns:

String:

metas

(
  • [$slotName=null]
  • [$between='']
  • [$alsoAsProperty='og']
)
String static

Returns text describing all the metas inline which have been added with setMeta()

Parameters:

  • [$slotName=null] String optional

    If provided, returns only the metas set while filling this slot.

  • [$between=''] String optional

    Optional text to insert between the <meta> tags or blocks of text.

  • [$alsoAsProperty='og'] String optional

    Also output this meta tag as a meta "property", see ogp.me

Returns:

String:

metasArray

(
  • [$slotName=null]
  • [$urls=true]
)
Array static

Return the array of metas added so far

Parameters:

  • [$slotName=null] String optional

    If provided, returns only the metas set while filling this slot. If you leave this empty, you get metas information for the "right" slots. If you pass false here, you will just get the entire $metas array without any processing.

  • [$urls=true] String optional

    If true, transforms all the 'src' values into URLs before returning.

Returns:

Array:

if $slotName is an array or true, returns array of $slotName => $metas, otherwise returns $metas

metasInline

(
  • [$slotName=null]
  • [$between='']
)
String static

Returns text describing all the metas inline which have been added with setMeta(), to be included between <meta></meta> tags.

Parameters:

  • [$slotName=null] String optional

    If provided, returns only the metas set while filling this slot.

  • [$between=''] String optional

    Optional text to insert between the blocks of meta text

Returns:

String:

output

(
  • [$new_output=null]
  • [$override=false]
)
String static

Used to get/set output that the Q/response handler should consult.

Parameters:

  • [$new_output=null] String optional

    Pass a string here to return as output, instead of the usual layout. Or, pass true here to indicate that we have already returned the output, and to skip rendering a layout.

  • [$override=false] Boolean optional

    If an output string is already set, calling this method wouldn't override it unless you pass true here.

Returns:

String:

Returns the output that was set, if any

redirect

(
  • $uri
  • $options
  • [$noProxy=false]
)
Boolean static

Sets a header to redirect to a given URI or URL.

Parameters:

  • $uri String

    The URL or internal URI to redirect to

  • $options Array

    An array of options that can include:

    • [loop=false] Boolean optional

      If false, and current URL is the same as the new one, skips setting the redirect header and just returns false.

    • [permanently=false] Boolean optional

      If true, sets response code as 304 instead of 302

    • [noProxy=false] Boolean optional

      If true, doesn't use the proxy mapping to determine URL

  • [$noProxy=false] Boolean optional

Returns:

Boolean:

Return whether the redirect header was set.

removeNotice

(
  • $key
)
Boolean static

Removes a notice

Parameters:

  • $key String

Returns:

Boolean:

true if notice has been deleted, false otherwise

retainSlot

(
  • [$toRetain=true]
)
static

Parameters:

  • [$toRetain=true] Boolean optional

    Defaults to true. Whether to cache the slot being rendered.

scriptData

(
  • [$slotName=null]
)
String static

Returns json describing all the script data that has been added to various slots

Parameters:

  • [$slotName=null] String optional

    By default, returns all the lines in their intended order. Pass a slot name here to return only the script lines added while filling this slot. Pass false here to return the script lines in the order they were added.

Returns:

String:

scriptData

(
  • [$slotName=null]
)
String static

Returns json describing all the templates that has been added to various slots

Parameters:

  • [$slotName=null] String optional

    By default, returns all the lines in their intended order. Pass a slot name here to return only the templates added while filling this slot. Pass false here to return the templates in the order they were added.

Returns:

String:

scriptLines

(
  • [$slotName=null]
  • [$without_script_data=false]
  • [$between='']
  • [$tags=true]
)
String static

Returns text describing all the scripts lines that have been added, to be included between <script></script> tags.

Parameters:

  • [$slotName=null] String optional

    By default, returns all the lines in their intended order. Pass a slot name here to return only the script lines added while filling this slot. Pass false here to return the script lines in the order they were added.

  • [$without_script_data=false] Boolean optional

    By default, a few script lines are prepended to insert the script data, for backward compatibility with apps that were built before scriptData was introduced. Pass true here if you don't want to include them in the result.

  • [$between=''] String optional

    Optional text to insert between the <style> tags or blocks of text.

  • [$tags=true] Boolean optional

    Whether to return the text already wrapped in