Zend_Controller_Response_Abstract

Base class for Zend_Controller responses

package Zend_Controller
subpackage Response
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Magic __toString functionality

__toString() : string

Proxies to \sendResponse() and returns response value as string using output buffering.

Returns

string

Append a named body segment to the body content array

append(string $name, string $content) : \Zend_Controller_Response_Abstract

If segment already exists, replaces with $content and places at end of array.

Parameters

$name

string

$content

string

Returns

\Zend_Controller_Response_Abstract

Append content to the body content

appendBody(string $content, null|string $name = null) : \Zend_Controller_Response_Abstract

Parameters

$content

string

$name

nullstring

Returns

\Zend_Controller_Response_Abstract

Can we send headers?

canSendHeaders(boolean $throw = false) : boolean

Parameters

$throw

boolean

Whether or not to throw an exception if headers have been sent; defaults to false

Exceptions

\Zend_Controller_Response_Exception

Returns

boolean

Clear all headers, normal and raw

clearAllHeaders() : \Zend_Controller_Response_Abstract

Returns

\Zend_Controller_Response_Abstract

Clear body array

clearBody(string $name = null) : boolean

With no arguments, clears the entire body array. Given a $name, clears just that named segment; if no segment matching $name exists, returns false to indicate an error.

Parameters

$name

string

Named segment to clear

Returns

boolean

Clears the specified HTTP header

clearHeader(string $name) : \Zend_Controller_Response_Abstract

Parameters

$name

string

Returns

\Zend_Controller_Response_Abstract

Clear headers

clearHeaders() : \Zend_Controller_Response_Abstract

Returns

\Zend_Controller_Response_Abstract

Clears the specified raw HTTP header

clearRawHeader(string $headerRaw) : \Zend_Controller_Response_Abstract

Parameters

$headerRaw

string

Returns

\Zend_Controller_Response_Abstract

Clear all {@link setRawHeader() raw HTTP headers}

clearRawHeaders() : \Zend_Controller_Response_Abstract

Returns

\Zend_Controller_Response_Abstract

Return the body content

getBody(boolean $spec = false) : string | array | null

If $spec is false, returns the concatenated values of the body content array. If $spec is boolean true, returns the body content array. If $spec is a string and matches a named segment, returns the contents of that segment; otherwise, returns null.

Parameters

$spec

boolean

Returns

stringarraynull

Retrieve the exception stack

getException() : array

Returns

array

Retrieve all exceptions of a given code

getExceptionByCode(mixed $code) : void

Parameters

$code

mixed

Retrieve all exceptions of a given message

getExceptionByMessage(string $message) : false | array

Parameters

$message

string

Returns

falsearray

Retrieve all exceptions of a given type

getExceptionByType(string $type) : false | array

Parameters

$type

string

Returns

falsearray

Return array of headers; see {@link $_headers} for format

getHeaders() : array

Returns

array

Retrieve HTTP response code

getHttpResponseCode() : integer

Returns

integer

Retrieve all {@link setRawHeader() raw HTTP headers}

getRawHeaders() : array

Returns

array

Does the response object contain an exception with a given code?

hasExceptionOfCode(integer $code) : boolean

Parameters

$code

integer

Returns

boolean

Does the response object contain an exception with a given message?

hasExceptionOfMessage(string $message) : boolean

Parameters

$message

string

Returns

boolean

Does the response object contain an exception of a given type?

hasExceptionOfType(string $type) : boolean

Parameters

$type

string

Returns

boolean

Insert a named segment into the body content array

insert(string $name, string $content, string $parent = null, boolean $before = false) : \Zend_Controller_Response_Abstract

Parameters

$name

string

$content

string

$parent

string

$before

boolean

Whether to insert the new segment before or after the parent. Defaults to false (after)

Returns

\Zend_Controller_Response_Abstract

Has an exception been registered with the response?

isException() : boolean

Returns

boolean

Is this a redirect?

isRedirect() : boolean

Returns

boolean

Echo the body segments

outputBody() : void

Prepend a named body segment to the body content array

prepend(string $name, string $content) : void

If segment already exists, replaces with $content and places at top of array.

Parameters

$name

string

$content

string

Whether or not to render exceptions (off by default)

renderExceptions(boolean $flag = null) : boolean

If called with no arguments or a null argument, returns the value of the flag; otherwise, sets it and returns the current value.

Parameters

$flag

boolean

Optional

Returns

boolean

Send all headers

sendHeaders() : \Zend_Controller_Response_Abstract

Sends any headers specified. If an \setHttpResponseCode() has been specified, it is sent with the first header.

Returns

\Zend_Controller_Response_Abstract

Send the response, including all headers, rendering exceptions if so requested.

sendResponse() : void

Set body content

setBody(string $content, null|string $name = null) : \Zend_Controller_Response_Abstract

If $name is not passed, or is not a string, resets the entire body and sets the 'default' key to $content.

If $name is a string, sets the named segment in the body array to $content.

Parameters

$content

string

$name

nullstring

Returns

\Zend_Controller_Response_Abstract

Register an exception with the response

setException(\Exception $e) : \Zend_Controller_Response_Abstract

Parameters

$e

\Exception

Returns

\Zend_Controller_Response_Abstract

Set a header

setHeader(string $name, string $value, boolean $replace = false) : \Zend_Controller_Response_Abstract

If $replace is true, replaces any headers already defined with that $name.

Parameters

$name

string

$value

string

$replace

boolean

Returns

\Zend_Controller_Response_Abstract

Set HTTP response code to use with headers

setHttpResponseCode(integer $code) : \Zend_Controller_Response_Abstract

Parameters

$code

integer

Returns

\Zend_Controller_Response_Abstract

Set raw HTTP header

setRawHeader(string $value) : \Zend_Controller_Response_Abstract

Allows setting non key => value headers, such as status codes

Parameters

$value

string

Returns

\Zend_Controller_Response_Abstract

Set redirect URL

setRedirect(string $url, integer $code = 302) : \Zend_Controller_Response_Abstract

Sets Location header and response code. Forces replacement of any prior redirects.

Parameters

$url

string

$code

integer

Returns

\Zend_Controller_Response_Abstract

Normalize a header name

_normalizeHeader(string $name) : string

Normalizes a header name to X-Capitalized-Names

Parameters

$name

string

Returns

string

 Properties

 

Flag; if true, when header operations are called after headers have been sent, an exception will be raised; otherwise, processing will continue as normal. Defaults to true.

$headersSentThrowsException : boolean

Default

true
see
 

Body content

$_body : array

Default

array()
 

Exception stack

$_exceptions : \Exception

Default

array()
 

Array of headers. Each header is an array with keys 'name' and 'value'

$_headers : array

Default

array()
 

Array of raw headers. Each header is a single string, the entire header to emit

$_headersRaw : array

Default

array()
 

HTTP response code to use in headers

$_httpResponseCode : integer

Default

200
 

Flag; is this response a redirect?

$_isRedirect : boolean

Default

false
 

Whether or not to render exceptions; off by default

$_renderExceptions : boolean

Default

false