Source for file jResponseJson.class.php
Documentation is available at jResponseJson.class.php
- <?php
- /**
- * @package jelix
- * @subpackage core_response
- * @author Laurent Jouanneau
- * @contributor Loic Mathaud
- * @copyright 2006-2007 Laurent Jouanneau
- * @copyright 2007 Loic Mathaud
- * @link http://www.jelix.org
- * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
- */
-
-
-
- /**
- * Json response
- * @package jelix
- * @subpackage core_response
- * @see jResponse
- * @since 1.0b1
- */
- final class jResponseJson extends jResponse {
- protected $_acceptSeveralErrors=false;
-
- /**
- * data in PHP you want to send
- * @var mixed
- */
- public $datas = null;
-
-
- public function output(){
- global $gJCoord;
- if($this->hasErrors()) return false;
- $this->_httpHeaders['Content-Type'] = "text/plain";
- $content = json_encode($this->datas);
- if($this->hasErrors()) return false;
-
- $this->_httpHeaders['Content-length'] = strlen($content);
- $this->sendHttpHeaders();
- echo $content;
- return true;
- }
-
- public function outputErrors(){
- global $gJCoord;
- $message = array();
- if(count($gJCoord->errorMessages)){
- $e = $gJCoord->errorMessages[0];
- $message['errorCode'] = $e[1];
- $message['errorMessage'] = '['.$e[0].'] '.$e[2].' (file: '.$e[3].', line: '.$e[4].')';
- }else{
- $message['errorMessage'] = 'Unknown error';
- $message['errorCode'] = -1;
- }
- $this->clearHttpHeaders();
- $this->_httpStatusCode ='500';
- $this->_httpStatusMsg ='Internal Server Error';
- $this->_httpHeaders['Content-Type'] = "text/plain";
- $content = json_encode($message);
- $this->_httpHeaders['Content-length'] = strlen($content);
- $this->sendHttpHeaders();
- echo $content;
- }
- }
-
- ?>
Documentation generated on Wed, 07 Sep 2011 13:47:45 +0200 by phpDocumentor 1.4.3