Example #1
0
 /**
  * Class constructor
  *
  * The request and response objects should be registered with the
  * controller, as should be any additional optional arguments; these will be
  * available via {@link getRequest()}, {@link getResponse()}, and
  * {@link getInvokeArgs()}, respectively.
  *
  * When overriding the constructor, please consider this usage as a best
  * practice and ensure that each is registered appropriately; the easiest
  * way to do so is to simply call parent::__construct($request, $response,
  * $invokeArgs).
  *
  * After the request, response, and invokeArgs are set, the
  * {@link $_helper helper broker} is initialized.
  *
  * When the broker is instantiated immediately a contextswitch is added
  * for defining the snippet context as the default context
  *
  * Finally, {@link init()} is called as the final action of
  * instantiation, and may be safely overridden to perform initialization
  * tasks; as a general rule, override {@link init()} instead of the
  * constructor to customize an action controller's instantiation.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param Zend_Controller_Response_Abstract $response
  * @param array $invokeArgs Any additional invocation arguments
  * @return void
  */
 public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 {
     $this->setRequest($request)->setResponse($response)->_setInvokeArgs($invokeArgs);
     $this->_helper = new Zend_Controller_Action_HelperBroker($this);
     $this->_context = $this->_helper->contextSwitch();
     if (!$this->_context->hasContext('snippet')) {
         $this->_context->addContext('snippet', array('suffix' => '', 'headers' => array('Content-Type' => $this->_contentType, 'Cache-Control' => sprintf(self::CACHE_CONTROL_HEADER_VALUE, self::CACHE_DEFAULT_TTL))));
     }
     $this->_context->setDefaultContext('snippet');
     $this->init();
 }
 /**
  * Setup the necessary contexts
  */
 public function init()
 {
     parent::init();
     $this->_contextSwitch = $this->_helper->getHelper('contextSwitch');
     if (!$this->_contextSwitch->hasContext('rss')) {
         $this->_contextSwitch->addContext('rss', array('suffix' => 'rss', 'headers' => array('Content-type' => 'application/rss+xml;charset=UTF-8')));
     }
     if (!$this->_contextSwitch->hasContext('atom')) {
         $this->_contextSwitch->addContext('atom', array('suffix' => 'atom', 'headers' => array('Content-type' => 'application/atom+xml')));
     }
     $this->_contextSwitch->addActionContext('list', array('rss', 'atom'))->addActionContext('index', array('rss', 'atom'))->initContext();
 }