X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=application%2Fcontrollers%2Fhelpers%2FSyjApi.php;h=029fe90275eb79d3db7a7b026083265c6bedabb0;hp=21aa9dd9f9b3fe5e4c88a2eb37bdaa4d8240eb5d;hb=014347ecde920ac7cb445fbed059f3b67f80336f;hpb=db98e1f62272cff0b425133aa3b909c5cfa6183d diff --git a/application/controllers/helpers/SyjApi.php b/application/controllers/helpers/SyjApi.php index 21aa9dd..029fe90 100644 --- a/application/controllers/helpers/SyjApi.php +++ b/application/controllers/helpers/SyjApi.php @@ -1,5 +1,5 @@ setNoRender(); - $layout = Zend_Layout::getMvcInstance(); - if (null !== $layout) { - $layout->disableLayout(); - } + $this->getActionController()->getHelper('SyjNoRender')->disableRender(); } public function setContentType($contentType) { @@ -51,6 +47,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; @@ -63,8 +73,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(); @@ -80,6 +90,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); }