Home > Backend Development > PHP Tutorial > Zend Framework tutorial: Detailed explanation of the encapsulation of the response object Zend_Controller_Response instance, controllerresponse_PHP tutorial

Zend Framework tutorial: Detailed explanation of the encapsulation of the response object Zend_Controller_Response instance, controllerresponse_PHP tutorial

WBOY
Release: 2016-07-12 08:57:42
Original
808 people have browsed it

Detailed explanation of the Zend Framework tutorial's response object encapsulation Zend_Controller_Response example, controllerresponse

This article describes the Zend Framework tutorial's response object encapsulation Zend_Controller_Response usage. Share it with everyone for your reference, the details are as follows:

Overview

The response object is logically a partner of the request object. Its purpose is to collect the message body and/or message headers, so it is possible to return a large number of results.

Basic implementation of Zend_Controller_Response response object

├── Response
│ ├── Abstract.php
│ ├── Cli.php
│ ├── Exception.php
│ ├── Http.php
│ └── HttpTestCase.php

Zend_Controller_Response_Abstract

abstract class Zend_Controller_Response_Abstract
{
 /**
  * Body content
  * @var array
  */
 protected $_body = array();
 /**
  * Exception stack
  * @var Exception
  */
 protected $_exceptions = array();
 /**
  * Array of headers. Each header is an array with keys 'name' and 'value'
  * @var array
  */
 protected $_headers = array();
 /**
  * Array of raw headers. Each header is a single string, the entire header to emit
  * @var array
  */
 protected $_headersRaw = array();
 /**
  * HTTP response code to use in headers
  * @var int
  */
 protected $_httpResponseCode = 200;
 /**
  * Flag; is this response a redirect?
  * @var boolean
  */
 protected $_isRedirect = false;
 /**
  * Whether or not to render exceptions; off by default
  * @var boolean
  */
 protected $_renderExceptions = false;
 /**
  * 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.
  *
  * @see canSendHeaders()
  * @var boolean
  */
 public $headersSentThrowsException = true;
 /**
  * Normalize a header name
  *
  * Normalizes a header name to X-Capitalized-Names
  *
  * @param string $name
  * @return string
  */
 protected function _normalizeHeader($name)
 {
  $filtered = str_replace(array('-', '_'), ' ', (string) $name);
  $filtered = ucwords(strtolower($filtered));
  $filtered = str_replace(' ', '-', $filtered);
  return $filtered;
 }
 /**
  * Set a header
  *
  * If $replace is true, replaces any headers already defined with that
  * $name.
  *
  * @param string $name
  * @param string $value
  * @param boolean $replace
  * @return Zend_Controller_Response_Abstract
  */
 public function setHeader($name, $value, $replace = false)
 {
  $this->canSendHeaders(true);
  $name = $this->_normalizeHeader($name);
  $value = (string) $value;
  if ($replace) {
   foreach ($this->_headers as $key => $header) {
    if ($name == $header['name']) {
     unset($this->_headers[$key]);
    }
   }
  }
  $this->_headers[] = array(
   'name' => $name,
   'value' => $value,
   'replace' => $replace
  );
  return $this;
 }
 /**
  * Set redirect URL
  *
  * Sets Location header and response code. Forces replacement of any prior
  * redirects.
  *
  * @param string $url
  * @param int $code
  * @return Zend_Controller_Response_Abstract
  */
 public function setRedirect($url, $code = 302)
 {
  $this->canSendHeaders(true);
  $this->setHeader('Location', $url, true)
    ->setHttpResponseCode($code);
  return $this;
 }
 /**
  * Is this a redirect?
  *
  * @return boolean
  */
 public function isRedirect()
 {
  return $this->_isRedirect;
 }
 /**
  * Return array of headers; see {@link $_headers} for format
  *
  * @return array
  */
 public function getHeaders()
 {
  return $this->_headers;
 }
 /**
  * Clear headers
  *
  * @return Zend_Controller_Response_Abstract
  */
 public function clearHeaders()
 {
  $this->_headers = array();
  return $this;
 }
 /**
  * Clears the specified HTTP header
  *
  * @param string $name
  * @return Zend_Controller_Response_Abstract
  */
 public function clearHeader($name)
 {
  if (! count($this->_headers)) {
   return $this;
  }
  foreach ($this->_headers as $index => $header) {
   if ($name == $header['name']) {
    unset($this->_headers[$index]);
   }
  }
  return $this;
 }
 /**
  * Set raw HTTP header
  *
  * Allows setting non key => value headers, such as status codes
  *
  * @param string $value
  * @return Zend_Controller_Response_Abstract
  */
 public function setRawHeader($value)
 {
  $this->canSendHeaders(true);
  if ('Location' == substr($value, 0, 8)) {
   $this->_isRedirect = true;
  }
  $this->_headersRaw[] = (string) $value;
  return $this;
 }
 /**
  * Retrieve all {@link setRawHeader() raw HTTP headers}
  *
  * @return array
  */
 public function getRawHeaders()
 {
  return $this->_headersRaw;
 }
 /**
  * Clear all {@link setRawHeader() raw HTTP headers}
  *
  * @return Zend_Controller_Response_Abstract
  */
 public function clearRawHeaders()
 {
  $this->_headersRaw = array();
  return $this;
 }
 /**
  * Clears the specified raw HTTP header
  *
  * @param string $headerRaw
  * @return Zend_Controller_Response_Abstract
  */
 public function clearRawHeader($headerRaw)
 {
  if (! count($this->_headersRaw)) {
   return $this;
  }
  $key = array_search($headerRaw, $this->_headersRaw);
  if ($key !== false) {
   unset($this->_headersRaw[$key]);
  }
  return $this;
 }
 /**
  * Clear all headers, normal and raw
  *
  * @return Zend_Controller_Response_Abstract
  */
 public function clearAllHeaders()
 {
  return $this->clearHeaders()
     ->clearRawHeaders();
 }
 /**
  * Set HTTP response code to use with headers
  *
  * @param int $code
  * @return Zend_Controller_Response_Abstract
  */
 public function setHttpResponseCode($code)
 {
  if (!is_int($code) || (100 > $code) || (599 < $code)) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Invalid HTTP response code');
  }
  if ((300 <= $code) && (307 >= $code)) {
   $this->_isRedirect = true;
  } else {
   $this->_isRedirect = false;
  }
  $this->_httpResponseCode = $code;
  return $this;
 }
 /**
  * Retrieve HTTP response code
  *
  * @return int
  */
 public function getHttpResponseCode()
 {
  return $this->_httpResponseCode;
 }
 /**
  * Can we send headers&#63;
  *
  * @param boolean $throw Whether or not to throw an exception if headers have been sent; defaults to false
  * @return boolean
  * @throws Zend_Controller_Response_Exception
  */
 public function canSendHeaders($throw = false)
 {
  $ok = headers_sent($file, $line);
  if ($ok && $throw && $this->headersSentThrowsException) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
  }
  return !$ok;
 }
 /**
  * Send all headers
  *
  * Sends any headers specified. If an {@link setHttpResponseCode() HTTP response code}
  * has been specified, it is sent with the first header.
  *
  * @return Zend_Controller_Response_Abstract
  */
 public function sendHeaders()
 {
  // Only check if we can send headers if we have headers to send
  if (count($this->_headersRaw) || count($this->_headers) || (200 != $this->_httpResponseCode)) {
   $this->canSendHeaders(true);
  } elseif (200 == $this->_httpResponseCode) {
   // Haven't changed the response code, and we have no headers
   return $this;
  }
  $httpCodeSent = false;
  foreach ($this->_headersRaw as $header) {
   if (!$httpCodeSent && $this->_httpResponseCode) {
    header($header, true, $this->_httpResponseCode);
    $httpCodeSent = true;
   } else {
    header($header);
   }
  }
  foreach ($this->_headers as $header) {
   if (!$httpCodeSent && $this->_httpResponseCode) {
    header($header['name'] . ': ' . $header['value'], $header['replace'], $this->_httpResponseCode);
    $httpCodeSent = true;
   } else {
    header($header['name'] . ': ' . $header['value'], $header['replace']);
   }
  }
  if (!$httpCodeSent) {
   header('HTTP/1.1 ' . $this->_httpResponseCode);
   $httpCodeSent = true;
  }
  return $this;
 }
 /**
  * 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.
  *
  * @param string $content
  * @param null|string $name
  * @return Zend_Controller_Response_Abstract
  */
 public function setBody($content, $name = null)
 {
  if ((null === $name) || !is_string($name)) {
   $this->_body = array('default' => (string) $content);
  } else {
   $this->_body[$name] = (string) $content;
  }
  return $this;
 }
 /**
  * Append content to the body content
  *
  * @param string $content
  * @param null|string $name
  * @return Zend_Controller_Response_Abstract
  */
 public function appendBody($content, $name = null)
 {
  if ((null === $name) || !is_string($name)) {
   if (isset($this->_body['default'])) {
    $this->_body['default'] .= (string) $content;
   } else {
    return $this->append('default', $content);
   }
  } elseif (isset($this->_body[$name])) {
   $this->_body[$name] .= (string) $content;
  } else {
   return $this->append($name, $content);
  }
  return $this;
 }
 /**
  * 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.
  *
  * @param string $name Named segment to clear
  * @return boolean
  */
 public function clearBody($name = null)
 {
  if (null !== $name) {
   $name = (string) $name;
   if (isset($this->_body[$name])) {
    unset($this->_body[$name]);
    return true;
   }
   return false;
  }
  $this->_body = array();
  return true;
 }
 /**
  * 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.
  *
  * @param boolean $spec
  * @return string|array|null
  */
 public function getBody($spec = false)
 {
  if (false === $spec) {
   ob_start();
   $this->outputBody();
   return ob_get_clean();
  } elseif (true === $spec) {
   return $this->_body;
  } elseif (is_string($spec) && isset($this->_body[$spec])) {
   return $this->_body[$spec];
  }
  return null;
 }
 /**
  * Append a named body segment to the body content array
  *
  * If segment already exists, replaces with $content and places at end of
  * array.
  *
  * @param string $name
  * @param string $content
  * @return Zend_Controller_Response_Abstract
  */
 public function append($name, $content)
 {
  if (!is_string($name)) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
  }
  if (isset($this->_body[$name])) {
   unset($this->_body[$name]);
  }
  $this->_body[$name] = (string) $content;
  return $this;
 }
 /**
  * Prepend a named body segment to the body content array
  *
  * If segment already exists, replaces with $content and places at top of
  * array.
  *
  * @param string $name
  * @param string $content
  * @return void
  */
 public function prepend($name, $content)
 {
  if (!is_string($name)) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
  }
  if (isset($this->_body[$name])) {
   unset($this->_body[$name]);
  }
  $new = array($name => (string) $content);
  $this->_body = $new + $this->_body;
  return $this;
 }
 /**
  * Insert a named segment into the body content array
  *
  * @param string $name
  * @param string $content
  * @param string $parent
  * @param boolean $before Whether to insert the new segment before or
  * after the parent. Defaults to false (after)
  * @return Zend_Controller_Response_Abstract
  */
 public function insert($name, $content, $parent = null, $before = false)
 {
  if (!is_string($name)) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Invalid body segment key ("' . gettype($name) . '")');
  }
  if ((null !== $parent) && !is_string($parent)) {
   require_once 'Zend/Controller/Response/Exception.php';
   throw new Zend_Controller_Response_Exception('Invalid body segment parent key ("' . gettype($parent) . '")');
  }
  if (isset($this->_body[$name])) {
   unset($this->_body[$name]);
  }
  if ((null === $parent) || !isset($this->_body[$parent])) {
   return $this->append($name, $content);
  }
  $ins = array($name => (string) $content);
  $keys = array_keys($this->_body);
  $loc = array_search($parent, $keys);
  if (!$before) {
   // Increment location if not inserting before
   ++$loc;
  }
  if (0 === $loc) {
   // If location of key is 0, we're prepending
   $this->_body = $ins + $this->_body;
  } elseif ($loc >= (count($this->_body))) {
   // If location of key is maximal, we're appending
   $this->_body = $this->_body + $ins;
  } else {
   // Otherwise, insert at location specified
   $pre = array_slice($this->_body, 0, $loc);
   $post = array_slice($this->_body, $loc);
   $this->_body = $pre + $ins + $post;
  }
  return $this;
 }
 /**
  * Echo the body segments
  *
  * @return void
  */
 public function outputBody()
 {
  $body = implode('', $this->_body);
  echo $body;
 }
 /**
  * Register an exception with the response
  *
  * @param Exception $e
  * @return Zend_Controller_Response_Abstract
  */
 public function setException(Exception $e)
 {
  $this->_exceptions[] = $e;
  return $this;
 }
 /**
  * Retrieve the exception stack
  *
  * @return array
  */
 public function getException()
 {
  return $this->_exceptions;
 }
 /**
  * Has an exception been registered with the response&#63;
  *
  * @return boolean
  */
 public function isException()
 {
  return !empty($this->_exceptions);
 }
 /**
  * Does the response object contain an exception of a given type&#63;
  *
  * @param string $type
  * @return boolean
  */
 public function hasExceptionOfType($type)
 {
  foreach ($this->_exceptions as $e) {
   if ($e instanceof $type) {
    return true;
   }
  }
  return false;
 }
 /**
  * Does the response object contain an exception with a given message&#63;
  *
  * @param string $message
  * @return boolean
  */
 public function hasExceptionOfMessage($message)
 {
  foreach ($this->_exceptions as $e) {
   if ($message == $e->getMessage()) {
    return true;
   }
  }
  return false;
 }
 /**
  * Does the response object contain an exception with a given code&#63;
  *
  * @param int $code
  * @return boolean
  */
 public function hasExceptionOfCode($code)
 {
  $code = (int) $code;
  foreach ($this->_exceptions as $e) {
   if ($code == $e->getCode()) {
    return true;
   }
  }
  return false;
 }
 /**
  * Retrieve all exceptions of a given type
  *
  * @param string $type
  * @return false|array
  */
 public function getExceptionByType($type)
 {
  $exceptions = array();
  foreach ($this->_exceptions as $e) {
   if ($e instanceof $type) {
    $exceptions[] = $e;
   }
  }
  if (empty($exceptions)) {
   $exceptions = false;
  }
  return $exceptions;
 }
 /**
  * Retrieve all exceptions of a given message
  *
  * @param string $message
  * @return false|array
  */
 public function getExceptionByMessage($message)
 {
  $exceptions = array();
  foreach ($this->_exceptions as $e) {
   if ($message == $e->getMessage()) {
    $exceptions[] = $e;
   }
  }
  if (empty($exceptions)) {
   $exceptions = false;
  }
  return $exceptions;
 }
 /**
  * Retrieve all exceptions of a given code
  *
  * @param mixed $code
  * @return void
  */
 public function getExceptionByCode($code)
 {
  $code  = (int) $code;
  $exceptions = array();
  foreach ($this->_exceptions as $e) {
   if ($code == $e->getCode()) {
    $exceptions[] = $e;
   }
  }
  if (empty($exceptions)) {
   $exceptions = false;
  }
  return $exceptions;
 }
 /**
  * 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.
  *
  * @param boolean $flag Optional
  * @return boolean
  */
 public function renderExceptions($flag = null)
 {
  if (null !== $flag) {
   $this->_renderExceptions = $flag &#63; true : false;
  }
  return $this->_renderExceptions;
 }
 /**
  * Send the response, including all headers, rendering exceptions if so
  * requested.
  *
  * @return void
  */
 public function sendResponse()
 {
  $this->sendHeaders();
  if ($this->isException() && $this->renderExceptions()) {
   $exceptions = '';
   foreach ($this->getException() as $e) {
    $exceptions .= $e->__toString() . "\n";
   }
   echo $exceptions;
   return;
  }
  $this->outputBody();
 }
 /**
  * Magic __toString functionality
  *
  * Proxies to {@link sendResponse()} and returns response value as string
  * using output buffering.
  *
  * @return string
  */
 public function __toString()
 {
  ob_start();
  $this->sendResponse();
  return ob_get_clean();
 }
}

Copy after login

Zend_Controller_Response_Http

/** Zend_Controller_Response_Abstract */
require_once 'Zend/Controller/Response/Abstract.php';
/**
 * Zend_Controller_Response_Http
 *
 * HTTP response for controllers
 *
 * @uses Zend_Controller_Response_Abstract
 * @package Zend_Controller
 * @subpackage Response
 */
class Zend_Controller_Response_Http extends Zend_Controller_Response_Abstract
{
}

Copy after login

Common Usage

If you want to send response output including message headers, use sendResponse().

$response->sendResponse();

Copy after login

Note: By default, the front controller calls sendResponse() after completing the dispatch request; generally, you do not need to call it. However, if you want to handle the response or use it for testing you can override the default behavior by setting the returnResponse flag using Zend_Controller_Front::returnResponse(true):

$front->returnResponse(true);
$response = $front->dispatch();
// do some more processing, such as logging...
// and then send the output:
$response->sendResponse();

Copy after login

Use response objects in action controllers. Write the results into the response object instead of directly rendering the output and sending the message header:

// Within an action controller action:
// Set a header
$this->getResponse()
 ->setHeader('Content-Type', 'text/html')
 ->appendBody($content);

Copy after login

Doing this will send all messages at once before displaying the content.

Note: If you use the action controller's view integration, you do not need to set the rendering view script in the corresponding object, because Zend_Controller_Action::render() does this by default.

If an exception occurs in the program, check the isException() flag of the response object and use getException() to obtain the exception. Additionally, it is possible to create custom response objects that redirect to error pages, log exception messages, beautifully format exception messages, and more.

The response object can be obtained after the front-end controller executes dispatch(), or the front-end controller is requested to return the response object instead of rendering output.

// retrieve post-dispatch:
$front->dispatch();
$response = $front->getResponse();
if ($response->isException()) {
 // log, mail, etc...
}
// Or, have the front controller dispatch() process return it
$front->returnResponse(true);
$response = $front->dispatch();
// do some processing...
// finally, echo the response
$response->sendResponse();

Copy after login

By default, exception messages are not displayed. The default settings can be overridden by calling renderExceptions(). Or enable the front controller's throwExceptions():

$response->renderExceptions(true);
$front->dispatch($request, $response);
// or:
$front->returnResponse(true);
$response = $front->dispatch();
$response->renderExceptions();
$response->sendResponse();
// or:
$front->throwExceptions(true);
$front->dispatch();

Copy after login

Processing message headers

As mentioned above, one of the important responsibilities of the response object is to collect and emit HTTP response headers, and accordingly there are a large number of methods:

canSendHeaders() is used to determine whether the message header has been sent. This method has an optional flag indicating whether to throw an exception when the message header has been sent. The default setting can be overridden by setting the headersSentThrowsException property to false.
setHeader($name, $value, $replace = false) is used to set individual message headers. By default, existing message headers with the same name will not be replaced, but $replace can be set to true to force replacement.
Before setting the message header, this method first checks canSendHeaders() to see if the operation is allowed and requests an exception to be thrown.
setRedirect($url, $code = 302) sets the HTTP positioning header to prepare for redirection. If an HTTP status code is provided, the redirection will use the status code.
It calls setHeader() internally and turns the $replace flag on to ensure that the positioning message header is only sent once.
getHeaders() returns an array of message headers, each element is an array with 'name' and 'value' keys.
clearHeaders() clears all registered key-value message headers.
setRawHeader() sets the raw message header without key-value pairs, such as HTTP status message header.
getRawHeaders() returns all registered raw message headers.
clearRawHeaders() clears all raw message headers.
clearAllHeaders() clears all message headers, including original message headers and key-value message headers.

In addition to the above methods, there are also accessors for getting and setting the HTTP response code of the current request, setHttpResponseCode() and getHttpResponseCode().

Named snippet

The corresponding object supports "named fragments". Allows you to split the message body into different fragments and arrange them in a certain order. Therefore the output is returned in a specific order. Internally, the body content is stored as an array, and a number of accessor methods can be used to indicate the position and name within the array.

For example, you can use the preDispatch() hook to add the header to the response object, then add the body content to the action controller, and finally add the footer to the postDispatch() hook.

// Assume that this plugin class is registered with the front controller
class MyPlugin extends Zend_Controller_Plugin_Abstract
{
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
  $response = $this->getResponse();
  $view = new Zend_View();
  $view->setBasePath('../views/scripts');
  $response->prepend('header', $view->render('header.phtml'));
 }
 public function postDispatch(Zend_Controller_Request_Abstract $request)
 {
  $response = $this->getResponse();
  $view = new Zend_View();
  $view->setBasePath('../views/scripts');
  $response->append('footer', $view->render('footer.phtml'));
 }
}
// a sample action controller
class MyController extends Zend_Controller_Action
{
 public function fooAction()
 {
  $this->render();
 }
}

Copy after login

In the above example, calling /my/foo will cause the content in the final response object to have the following structure:

array(
 'header' => ..., // header content
 'default' => ..., // body content from MyController::fooAction()
 'footer' => ... // footer content
);

Copy after login

When rendering the response, it will be rendered in the order of the elements in the array.

A number of methods can be used to handle named fragments:

Both setBody() and appendBody() allow passing in a $name parameter, indicating a named fragment. If this argument is provided, the specified named fragment will be overwritten and created if it does not exist. If the $name parameter is not passed to setBody(), the entire body content will be reset. If no $name argument is passed to appendBody(), the content is appended to the 'default' named fragment.
prepend($name, $content) will create a fragment named $name and place it at the beginning of the array. If the fragment exists, it will be removed first.
append($name, $content) will create a fragment named $name and place it at the end of the array. If the fragment exists, it will be removed first.
insert($name, $content, $parent = null, $before = false) will create a $name named fragment. If the $parent parameter is provided, the new fragment will be placed at
depending on the value of $before before or after $parent. If the fragment exists, it will be removed first.
clearBody($name = null) If the $name parameter is provided, the fragment will be deleted, otherwise it will delete all.
getBody($spec = false) If the $spec parameter is a fragment name, the field will be obtained. If the $spec parameter is false, a sequential chain of named fragments in string format will be returned. If the $spec parameter is true, return the body content array.

Test exception in response object

As mentioned above, by default, exceptions during the distribution process will be registered in the response object. Exceptions are registered in a heap, allowing you to throw all exceptions - program exceptions, dispatch exceptions, plug-in exceptions, etc. If you want to check for or log a specific exception, you may want to use the response object's exception API:

setException(Exception $e) registers an exception.
isException() determines whether the exception is registered.
getException() returns the entire exception heap.
hasExceptionOfType($type) determines whether an exception of a specific class is in the heap.
hasExceptionOfMessage($message) determines whether the exception with the specified message is in the heap.
hasExceptionOfCode($code) determines whether the exception with the specified code is in the heap.
getExceptionByType($type) Gets all exceptions of a specific class in the heap. Returns false if not, otherwise returns an array.
getExceptionByMessage($message) Gets all exceptions in the heap with a specific message. Returns false if not, otherwise returns an array.
getExceptionByCode($code) Gets all exceptions in the heap with a specific code. Returns false if not, otherwise returns an array.
renderExceptions($flag) Sets a flag indicating whether exceptions in a response should be sent when sending it.

Custom response object

The purpose of the response object is first to collect message headers and content from a large number of actions and plug-ins, and then return them to the client; secondly, the response object also collects any exceptions that occur to handle or return these exceptions, or to the terminal User hides them.

The base class of response is Zend_Controller_Response_Abstract, any subclass created must inherit this class or its derived class. A number of available methods have been listed in previous chapters.

Reasons for customizing response objects include modifying how the returned content is output based on the request environment (for example: not sending headers in CLI and PHP-GTK requests), adding the ability to return a final view of the content stored in a named fragment, etc. wait.

Readers who are interested in more zend-related content can check out the special topics of this site: "Zend FrameWork Framework Introductory Tutorial", "php Excellent Development Framework Summary", "Yii Framework Introduction and Summary of Common Techniques", "ThinkPHP Introductory Tutorial" , "php object-oriented programming introductory tutorial", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Detailed explanation of Autoloading usage in Zend Framework tutorial
  • Resource Autoloading usage example in Zend Framework tutorial
  • Zend Framework tutorial Controller Usage Analysis of MVC Framework
  • Zend Framework Tutorial Detailed Explanation of Function Zend_Controller_Router
  • Zend Framework Tutorial Detailed Explanation of Zend_Controller_Plugin Plugin Usage
  • Zend Framework Tutorial Encapsulation of Request Object Zend_Controller_Request Instance Detailed explanation
  • Detailed explanation of Zend Framework tutorial’s action base class Zend_Controller_Action
  • Zend Framework tutorial’s detailed explanation of usage of distributor Zend_Controller_Dispatcher
  • Zend Framework tutorial detailed explanation of usage of front-end controller Zend_Controller_Front
  • Detailed explanation of usage of view component Zend_View in Zend Framework tutorial
  • Detailed explanation of usage of Loader and PluginLoader in Zend Framework tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106891.htmlTechArticleZend Framework tutorial's response object encapsulation Zend_Controller_Response example detailed explanation, controllerresponse This example describes the Zend Framework tutorial's response object Encapsulate Zend_Controll...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template