X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=application%2Fcontrollers%2Fhelpers%2FSyjApi.php;h=bfb97927d1a2aeb97d51573869a4a040308d2646;hp=21aa9dd9f9b3fe5e4c88a2eb37bdaa4d8240eb5d;hb=c1aeb7538786d8c9f3b3337c0b71e21ef89d9c77;hpb=69cbaf628f5576754d4553c021315188e22d24af diff --git a/application/controllers/helpers/SyjApi.php b/application/controllers/helpers/SyjApi.php index 21aa9dd..bfb9792 100644 --- a/application/controllers/helpers/SyjApi.php +++ b/application/controllers/helpers/SyjApi.php @@ -8,6 +8,7 @@ class Syj_Controller_Action_Helper_SyjApi extends Zend_Controller_Action_Helper_ protected $_checkIfNoneMatch = false; protected $_body = ''; protected $_code = 200; + protected $_redirect = ''; public function init() { $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); @@ -51,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; @@ -80,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); }