waResponse

Generates response to user request

Contents...

To obtain an instance of this class, call method wa()->getResponse(); e.g.,:

wa()->getResponse()->getHeader('Content-type')

Methods

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

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

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

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

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

Example

wa()->getResponse()->getCss();

public function getHeader ($name = null)

Returns response header value.

Parameters

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

Example

wa()->getResponse()->getJs();

public function getMeta ($name = null)

Returns the META data: page title ('title'), META tags keywords ('keywords'), description ('description').

Parameters

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

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

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

Example

wa()->getResponse()->setMeta('keywords', $keywords);

public function setStatus ($code)

Sets server response status.

Parameters

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

Example

wa()->getResponse()->setTitle('My Online Store');