public function direct($data = null, $errors = null, $sendNow = true, $keepLayouts = false) { $resp = $this->_createResponseObject($data, $errors); if ($sendNow) { return $this->_json->sendJson($resp, $keepLayouts); } return $this->_json->encodeJson($resp, $keepLayouts); }
/** * Encode JSON response and immediately send * * @param mixed $data * @param boolean|array $keepLayouts * NOTE: if boolean, establish $keepLayouts to true|false * if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false * if $keepLayouts and parmas for Zend_Json::encode are required * then, the array can contains a 'keepLayout'=>true|false * that will not be passed to Zend_Json::encode method but will be passed * to Zend_View_Helper_Json * @param bool $wrap * @return string|void */ public function sendJson($data, $keepLayouts = false, $wrap = true) { if (!is_array($data)) { return parent::sendJson($data, $keepLayouts); } if (isset($data['success']) && !is_bool($data['success'])) { $data['success'] = (bool) $data['success']; } if ($wrap) { $messages = Axis::message()->getAll(); // if (isset(false === $data['success']) && $data['success']) { // unset($messages['success']); // } $data = array_merge(array('messages' => $messages), $data); } if ($this->_data) { $data = array_merge_recursive($this->_data, $data); } $data = $this->encodeJson($data, $keepLayouts); $response = $this->getResponse(); $response->setBody($data); if (!$this->suppressExit) { Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush(); //Axis_FirePhp $response->sendResponse(); exit; } return $data; }
public function direct($arrayData) { header('Content-type: application/json'); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept"); $json = new Zend_Controller_Action_Helper_Json(); $json->sendJson($arrayData); }
/** * Kick jobs * - server * - tube * - count : number of jobs to kick */ public function kickAction() { $tube = $this->_getParam("tube"); $count = $this->_getParam("count", 1); try { // Connect to the server $messageQueue = $this->getServer(); $messageQueue->useTube($tube); $messageQueue->kick($count); $response = ""; } catch (Exception $e) { $this->getResponse()->setHttpResponseCode(500); $response = $e->getMessage(); } // Send Json response $this->jsonHelper->sendJson($response); $this->jsonHelper->getResponse()->sendResponse(); }