Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Controller_Response_Abstract Class Reference

Public Member Functions

 setHeader ($name, $value, $replace=false)
 Set a header.
 
 setRedirect ($url, $code=302)
 Set redirect URL.
 
 isRedirect ()
 Is this a redirect?
 
 getHeaders ()
 Return array of headers; see $_headers for format.
 
 clearHeaders ()
 Clear headers.
 
 clearHeader ($name)
 Clears the specified HTTP header.
 
 setRawHeader ($value)
 Set raw HTTP header.
 
 getRawHeaders ()
 Retrieve all raw HTTP headers.
 
 clearRawHeaders ()
 Clear all raw HTTP headers.
 
 clearRawHeader ($headerRaw)
 Clears the specified raw HTTP header.
 
 clearAllHeaders ()
 Clear all headers, normal and raw.
 
 setHttpResponseCode ($code)
 Set HTTP response code to use with headers.
 
 getHttpResponseCode ()
 Retrieve HTTP response code.
 
 canSendHeaders ($throw=false)
 Can we send headers?
 
 sendHeaders ()
 Send all headers.
 
 setBody ($content, $name=null)
 Set body content.
 
 appendBody ($content, $name=null)
 Append content to the body content.
 
 clearBody ($name=null)
 Clear body array.
 
 getBody ($spec=false)
 Return the body content.
 
 append ($name, $content)
 Append a named body segment to the body content array.
 
 prepend ($name, $content)
 Prepend a named body segment to the body content array.
 
 insert ($name, $content, $parent=null, $before=false)
 Insert a named segment into the body content array.
 
 outputBody ()
 Echo the body segments.
 
 setException (Exception $e)
 Register an exception with the response.
 
 getException ()
 Retrieve the exception stack.
 
 isException ()
 Has an exception been registered with the response?
 
 hasExceptionOfType ($type)
 Does the response object contain an exception of a given type?
 
 hasExceptionOfMessage ($message)
 Does the response object contain an exception with a given message?
 
 hasExceptionOfCode ($code)
 Does the response object contain an exception with a given code?
 
 getExceptionByType ($type)
 Retrieve all exceptions of a given type.
 
 getExceptionByMessage ($message)
 Retrieve all exceptions of a given message.
 
 getExceptionByCode ($code)
 Retrieve all exceptions of a given code.
 
 renderExceptions ($flag=null)
 Whether or not to render exceptions (off by default)
 
 sendResponse ()
 Send the response, including all headers, rendering exceptions if so requested.
 
 __toString ()
 Magic __toString functionality.
 

Public Attributes

 $headersSentThrowsException = true
 

Protected Member Functions

 _normalizeHeader ($name)
 Normalize a header name.
 

Protected Attributes

 $_body = array()
 
 $_exceptions = array()
 
 $_headers = array()
 
 $_headersRaw = array()
 
 $_httpResponseCode = 200
 
 $_isRedirect = false
 
 $_renderExceptions = false
 

Member Function Documentation

__toString ( )

Magic __toString functionality.

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

Returns
string
_normalizeHeader (   $name)
protected

Normalize a header name.

Normalizes a header name to X-Capitalized-Names

Parameters
string$name
Returns
string
append (   $name,
  $content 
)

Append a named body segment to the body content array.

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

Parameters
string$name
string$content
Returns
Zend_Controller_Response_Abstract
appendBody (   $content,
  $name = null 
)

Append content to the body content.

Parameters
string$content
null | string$name
Returns
Zend_Controller_Response_Abstract
canSendHeaders (   $throw = false)

Can we send headers?

Parameters
boolean$throwWhether or not to throw an exception if headers have been sent; defaults to false
Returns
boolean
Exceptions
Zend_Controller_Response_Exception
clearAllHeaders ( )

Clear all headers, normal and raw.

Returns
Zend_Controller_Response_Abstract
clearBody (   $name = null)

Clear body array.

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
string$nameNamed segment to clear
Returns
boolean
clearHeader (   $name)

Clears the specified HTTP header.

Parameters
string$name
Returns
Zend_Controller_Response_Abstract
clearHeaders ( )

Clear headers.

Returns
Zend_Controller_Response_Abstract
clearRawHeader (   $headerRaw)

Clears the specified raw HTTP header.

Parameters
string$headerRaw
Returns
Zend_Controller_Response_Abstract
clearRawHeaders ( )
getBody (   $spec = false)

Return the body content.

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
boolean$spec
Returns
string|array|null
getException ( )

Retrieve the exception stack.

Returns
array
getExceptionByCode (   $code)

Retrieve all exceptions of a given code.

Parameters
mixed$code
Returns
void
getExceptionByMessage (   $message)

Retrieve all exceptions of a given message.

Parameters
string$message
Returns
false|array
getExceptionByType (   $type)

Retrieve all exceptions of a given type.

Parameters
string$type
Returns
false|array
getHeaders ( )

Return array of headers; see $_headers for format.

Returns
array
getHttpResponseCode ( )

Retrieve HTTP response code.

Returns
int
getRawHeaders ( )

Retrieve all raw HTTP headers.

Returns
array
hasExceptionOfCode (   $code)

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

Parameters
int$code
Returns
boolean
hasExceptionOfMessage (   $message)

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

Parameters
string$message
Returns
boolean
hasExceptionOfType (   $type)

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

Parameters
string$type
Returns
boolean
insert (   $name,
  $content,
  $parent = null,
  $before = false 
)

Insert a named segment into the body content array.

Parameters
string$name
string$content
string$parent
boolean$beforeWhether to insert the new segment before or after the parent. Defaults to false (after)
Returns
Zend_Controller_Response_Abstract
isException ( )

Has an exception been registered with the response?

Returns
boolean
isRedirect ( )

Is this a redirect?

Returns
boolean
outputBody ( )

Echo the body segments.

Returns
void
prepend (   $name,
  $content 
)

Prepend a named body segment to the body content array.

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

Parameters
string$name
string$content
Returns
void
renderExceptions (   $flag = null)

Whether or not to render exceptions (off by default)

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

Parameters
boolean$flagOptional
Returns
boolean
sendHeaders ( )

Send all headers.

Sends any headers specified. If an HTTP response code has been specified, it is sent with the first header.

Returns
Zend_Controller_Response_Abstract
sendResponse ( )

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

Returns
void
setBody (   $content,
  $name = null 
)

Set body content.

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
string$content
null | string$name
Returns
Zend_Controller_Response_Abstract
setException ( Exception  $e)

Register an exception with the response.

Parameters
Exception$e
Returns
Zend_Controller_Response_Abstract
setHeader (   $name,
  $value,
  $replace = false 
)

Set a header.

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

Parameters
string$name
string$value
boolean$replace
Returns
Zend_Controller_Response_Abstract
setHttpResponseCode (   $code)

Set HTTP response code to use with headers.

Parameters
int$code
Returns
Zend_Controller_Response_Abstract
setRawHeader (   $value)

Set raw HTTP header.

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

Parameters
string$value
Returns
Zend_Controller_Response_Abstract
setRedirect (   $url,
  $code = 302 
)

Set redirect URL.

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

Parameters
string$url
int$code
Returns
Zend_Controller_Response_Abstract

Member Data Documentation

$_body = array()
protected
$_exceptions = array()
protected
$_headers = array()
protected
$_headersRaw = array()
protected
$_httpResponseCode = 200
protected
$_isRedirect = false
protected
$_renderExceptions = false
protected
$headersSentThrowsException = true