/** * Sending error message 404 * * @return void */ static function error404() { if (!isset(self::$request->output)) { return '<h1>404</h1><p>' . Rajax_Route::$errorMessage . '</p>'; } switch (strtolower(self::$request->output)) { case 'html': return '<h1>404</h1><p>' . Rajax_Route::$errorMessage . '</p>'; break; case 'json': return json_encode(array('status' => 404, 'message' => Rajax_Route::$errorMessage)); break; case 'xml': $output = new Rajax_XML(array(0 => array('status' => 404, 'message' => Rajax_Route::$errorMessage))); return $output->getXML(); break; } }
/** * Output the gathered data from db * given format outputs = xml,json,html * * $secureOutput = array('username','registereddate') * With secure output you control which column is able to output within this request * * @param array/object $resultList * @param string $format * @param array $secureOutput * @return html/xml/json */ public function output($resultList, $secureOutput = array()) { if (!$resultList || empty(Rajax_Application::$request->options) && Rajax_Application::$request->output == 'html') { return false; } if (!is_array($resultList) && !is_object($resultList)) { throw new Exception('Output expects an object/array as resultList'); } //$resultList = $this->_secureTheOutput($resultList,$secureOutput); if ($this->_isSingleRow($resultList)) { $data = $resultList; unset($resultList); $resultList[0] = $data; } $resultList = $this->_convertUTF8($resultList); switch (strtolower(Rajax_Application::$request->output)) { case 'json': if (!Rajax_Application::$fallback) { header('Content-type: application/json'); } print new Rajax_JSON($resultList); break; case 'xml': if (!Rajax_Application::$fallback) { header('Content-type: text/xml'); } $xml = new Rajax_XML($resultList); print $xml->getXML(); break; case 'html': if (!Rajax_Application::$fallback) { header('Content-type: text/html'); } $html = new Rajax_HTML($resultList); if ($this->options['_type'] == 'template' && isset($this->options['file'])) { if (is_array($resultList) && !empty($resultList)) { foreach ($resultList as $result) { $html->getTemplate($this->options['file'], $result); } } } else { if ($this->options['_type'] == 'template' && isset($this->options['odd']) && isset($this->options['even'])) { $count = 1; if (is_array($resultList) && !empty($resultList)) { foreach ($resultList as $result) { if ($count == 1) { $html->getTemplate($this->options['odd'], $result); $count = 2; } else { $html->getTemplate($this->options['even'], $result); $count = 1; } } } } else { print $html->getHTML(); } } break; } return true; }