Exemplo n.º 1
0
 /**
  * Send response to browser with json content type
  */
 public function sendResponse()
 {
     $this->_response = Mage::app()->getResponse();
     //check redirect
     if ($this->_response->isRedirect()) {
         $headers = $this->_response->getHeaders();
         $redirect = '';
         foreach ($headers as $header) {
             if ("Location" == $header["name"]) {
                 $redirect = $header["value"];
                 break;
             }
         }
         if ($redirect) {
             $this->setRedirect($redirect);
         }
     }
     $this->_response->clearHeaders();
     $this->_response->setHeader('Content-Type', 'application/json');
     $this->_response->clearBody();
     $this->_response->setBody($this->toJson());
     $this->_response->sendResponse();
     exit;
 }
Exemplo n.º 2
0
 public function run(Zend_Controller_Response_Abstract $response = null)
 {
     $args = array($this);
     $this->runCallback(self::CB_BEFORE_RUN, $args);
     if ($response === null) {
         $response = new Zend_Controller_Response_Http();
     }
     $this->response = $response;
     $action = $this->getCurrentAction();
     $this->request->setActionName($action);
     ob_start();
     $this->actionRun($action);
     if ($this->response->isRedirect() && $this->completeRequest->isXmlHttpRequest()) {
         $url = null;
         foreach ($response->getHeaders() as $header) {
             if ($header['name'] == 'Location') {
                 $url = $header['value'];
             }
         }
         $code = $response->getHttpResponseCode();
         // change request to ajax response
         $response->clearAllHeaders();
         $response->clearBody();
         $response->setHttpResponseCode(200);
         $response->setHeader("Content-Type", "application/json; charset=UTF-8", true);
         $response->setBody(Am_Controller::getJson(array('ngrid-redirect' => $url, 'status' => $code)));
         //throw new Am_Exception_Redirect($url);
     } else {
         $response->appendBody(ob_get_clean());
     }
     unset($this->response);
     return $response;
 }
Exemplo n.º 3
0
 /**
  * reset body output values
  *
  * @param null|string $name
  *
  * @return void
  */
 public function clearBody($name = null)
 {
     $this->outputBodyCallback = null;
     return parent::clearBody($name);
 }