X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=application%2Fcontrollers%2Fhelpers%2FSyjApi.php;h=6016f99a75c6d76a8aa5a2102729396fad63ef89;hp=37b010afcc95146b64f897fc53de3183a79136e4;hb=f9496a89b1cdbb8bed26742f19fc36559e502264;hpb=1d1b5940442782d78f796d8608e63328e2e8783b diff --git a/application/controllers/helpers/SyjApi.php b/application/controllers/helpers/SyjApi.php index 37b010a..6016f99 100644 --- a/application/controllers/helpers/SyjApi.php +++ b/application/controllers/helpers/SyjApi.php @@ -1,5 +1,5 @@ setBody(json_encode($data)) ->setContentType('application/json'); + return $this; } public function setBody($body) { @@ -50,6 +52,20 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ return $this->_code; } + public function setRedirect($url, $code = 0) { + $this->_redirect = (string)$url; + if (is_numeric($code) && (int)$code >= 300 && (int)$code < 400) { + $this->_code; + } else if (!isset($this->_code)) { + $this->code = 301; + } + return $this; + } + + public function getRedirect() { + return $this->_redirect; + } + public function setCheckIfNoneMatch($check) { $this->_checkIfNoneMatch = (boolean)$check; return $this; @@ -62,8 +78,8 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ public function postDispatch() { $response = $this->getResponse(); - $response->setHeader('Content-Type', $this->_contentType) - ->setHeader('Content-Length', strlen($this->_body)); + $response->setHeader('Content-Type', $this->_contentType, true) + ->setHeader('Content-Length', strlen($this->_body), true); if ($this->_checkIfNoneMatch) { $request = $this->getRequest(); @@ -79,6 +95,10 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ $response->setHeader ('Etag', $etag); } + if ($this->_redirect) { + $response->setHeader ('Location', $this->_redirect); + } + $response->setHttpResponseCode($this->_code) ->setBody($this->_body); }