To obtain an instance of this class, call method wa()->getResponse()
; e.g.,:
wa()->getResponse()->getHeader('Content-type')
Methods
-
addCss
Adds a URL to the CSS file list.
-
addGoogleAnalytics
Adds a string of JavaScript code for Google Analytics.
-
addHeader
Adds a header to be sent by server in response to user request.
-
addJs
Adds a URL to the JavaScript file list.
-
getCss
Returns the list of previously added CSS file URLs.
-
getHeader
Returns response header value.
-
getJs
Returns the list of JavaScript file URLs added to the response.
-
getMeta
Returns the META data.
-
getStatus
Returns the server response code.
-
getTitle
Return the page TITLE value.
-
redirect
Redirects the user to specified URL.
-
sendHeaders
Sends all previously added headers.
-
setCookie
Sets a cookie value.
-
setMeta
Sets a META value.
-
setStatus
Sets server response status.
-
setTitle
Sets a value for META item
title
. -
getCanonical
Returns the canonical link URL for the current page.
-
setCanonical
Sets the canonical link URL for the current page.
-
setLastModified
Sets the
Last-Modified
header value. -
handleIfModifiedSince
Handles the
Last-Modified
header value.
public function addCss ($url, $app_id = false)
Adds a URL to the CSS file list. All added CSS file URLs are available in Smarty templates by means of method {$wa->css()}
.
Parameters
-
$url
Relative URL of a CSS file. If
$app_id
is specified, then the URL must be relative to the specified app's directory URL. Otherwise the CSS file URL must be relative to the framework root directory URL. -
$app_id
Optional app id.
Example
wa()->getResponse()->addCss('css/myapp.css', 'myapp');
public function addGoogleAnalytics ($str)
Adds a JavaScript code string for Google Analytics. Code added for Google Analytics is included in HTML templates by means of method {$wa->headJs()}
.
Parameters
-
$str
JavaScript code string.
public function addHeader ($name, $value, $replace = true)
Adds a header to be sent by server in response to user request. All added headers will be sent to user when method sendHeaders is called.
Parameters
-
$name
Header name.
-
$value
Header value.
-
$replace
Flag requiring to replace the previously set value for the specified header.
Example
wa()->getResponse()->addHeader('Content-type', 'application/json');
public function addJs ($url, $app_id = false)
Adds a URL to the JavaScript file list. All added URLs are available in Smarty templates by means of method {$wa->js()}
.
Parameters
-
$url
URL of a JavaScript file. If
$app_id
is specified, then the URL must be relative to the specified app's directory URL. Otherwise the JavaScript file URL must be relative to the framework root directory URL. -
$app_id
Optional app id.
Example
wa()->getResponse()->addJs('js/myapp.js', 'myapp');
public function getCss ($html = true, $strict = false)
Returns the list of previously added CSS file URLs.
Parameters
-
$html
Optional flag requiring to return HTML code for including CSS files in a HTML template. If
false
is specified, the method returns an array of CSS file URLs. -
$strict
Flag changing default HTML format to XHTML when
$html
parameter is set totrue
.
Example
wa()->getResponse()->getCss();
public function getHeader ($name = null)
Returns response header value.
Parameters
-
$name
Id of the header whose value must be returned. If not specified, entire header array is returned.
Example
wa()->getResponse()->addHeader('Content-type', 'application/json'); wa()->getResponse()->getHeader('Content-type');
Result
application/json
public function getJs ($html = true)
Returns the list of JavaScript file URLs added to the response.
Parameters
-
$html
Optional flag requiring to return HTML code for including JavaScript files in a HTML template. If
false
is specified, the method returns an array of CSS file URLs.
Example
wa()->getResponse()->getJs();
public function getMeta ($name = null)
Returns the META data: page title ('title'
), META tags keywords ('keywords'
), description ('description'
).
Parameters
-
$name
META data item id whose value must be returned. If not specified, the method returns entire META data array.
Example
wa()->getResponse()->getMeta('keywords');
public function getStatus()
Returns the server response code.
Example
wa()->getResponse()->setStatus(200); wa()->getResponse()->getStatus();
Result
200
public function getTitle()
Return the page TITLE value.
Example
wa()->getResponse()->setTitle('My Online Store'); wa()->getResponse()->getTitle();
Result
My Online Store
public function redirect ($url, $code = null)
Redirects the user to specified URL.
Parameters
-
$url
URL to redirect to.
-
$code
Server response code to return with the redirect.
Example
wa()->getResponse()->redirect('http://otherdomain.com/', 301);
public function sendHeaders()
Sends all previously added headers.
Example
wa()->getResponse()->addHeader('Content-type', 'application/json'); wa()->getResponse()->sendHeaders();
public function setCookie ($name, $value, $expire = null, $path = null, $domain = '', $secure = false, $http_only = false)
Sets a cookie value using PHP function setcookie
.
Parameters
-
$name
Cookie item id.
-
$value
Cookie value.
-
$expire
Expiration time.
-
$path
Path to URL "subdirectory" within which a cookie item must be valid.
-
$domain
Domain name for which a cookie item must be valid.
-
$secure
Flag making a cookie value available only if passed over HTTPS.
-
$http_only
Flag making a cookie value accessible only via HTTP and not accessible to client scripts (JavaScript).
Example
wa()->getResponse()->setCookie('code', $code, time() + 30 * 86400, null, '', false, true);
public function setMeta ($name, $value = null)
Sets a META value. This value is accessible in Smarty templates by means of method {$wa->meta()}
.
Parameters
-
$name
META data item id: page title (
'title'
), META tags keywords ('keywords'
), description ('description'
). -
$value
Item value.
Example
wa()->getResponse()->setMeta('keywords', $keywords);
public function setStatus ($code)
Sets server response status.
Parameters
-
$code
Server status code.
Example
wa()->getResponse()->setStatus(404);
public function setTitle ($title)
Sets the page TITLE value. This value is accessible in Smarty templates by means of method {$wa->title()}
.
Parameters
-
$title
Page TITLE value.
Example
wa()->getResponse()->setTitle('My Online Store');
public function getCanonical()
Returns the canonical link URL for the current page.
Example
$canonical_link = wa()->getResponse()->getCanonical();
public function setCanonical ($canonical_url = null, $with_header_link = true)
Sets the canonical link URL for the current page. HTML tag link
with the specified URL is included in the HTML code returned by Smarty helper {$wa->head()}
.
Parameters
-
$canonical_url
Canonical link URL to be set for the current page. If no value is specified then the request URL without GET parameters is considered canonical.
-
$with_header_link
Flag denoting that header Link with the canonical lnk URL must be sent with the response contents.
Example
wa()->getResponse()->setCanonical($my_canonical_url);
public function setLastModified ($last_modified_datetime)
Sets the Last-Modified
header value. It is allowed to call this method several times before headers have been sent. The effective header value will the one set during the most recent method call.
This method is used in combination with handleIfModifiedSince().
Parameters
-
$last_modified_datetime
String value of date and time supported by the
strtotime()
function.
Example
$response = wa()->getResponse(); $response->setLastModified($last_modified_datetime); $response->handleIfModifiedSince();
public function handleIfModifiedSince()
Handles the Last-Modified
header value set by means of the setLastModified() method. If the effective value of the Last-Modified
header is equal to the If-Modified-Since
header value then server response code 304 is set, headers are sent and further request processing is terminated.
Example
$response = wa()->getResponse(); $response->setLastModified($last_modified_datetime); $response->handleIfModifiedSince();