Example #1
0
 static function render($type, $value = null, $params = array())
 {
     if ($type === false) {
         self::$params['nothing'] = true;
         return;
     }
     if (is_int(strpos($type, '#'))) {
         /**
          * We're rendering a controller/action file.
          * In this case, $value holds the params, and we only change
          * the 'render' value and return. We can't call the
          * render file within this or any function because of variables scope.
          * 
          * This is expected to occur in a controller, therefore in the controller one must
          * also return; after calling this function, so further code won't be executed.
          */
         list($ctrl, $act) = explode('#', parse_url_token($type));
         self::parse_parameters($value);
         self::$render = VIEWPATH . "{$ctrl}/{$act}.php";
         return;
     }
     # Running after-filters.
     ActionController::run_after_filters();
     self::parse_parameters($params);
     if ($type == 'json') {
         header('Content-Type: application/json; charset=utf-8');
         if (is_array($value)) {
             $value = to_json($value);
         }
         echo $value;
         exit;
     } elseif ($type == 'xml') {
         header('Content-type: application/rss+xml; charset=UTF-8');
         if (is_array($value) || is_object($value)) {
             $root = isset($params['root']) ? $params['root'] : 'response';
             $value = to_xml($value, $root);
         }
         echo $value;
         exit;
     } elseif ($type == 'inline') {
         self::$params['render_type'] = 'inline';
         self::$params['render_value'] = $value;
         include SYSROOT . 'action_view/render_markup_default.php';
     }
 }
<?php

if (Request::$format == 'html') {
    header('Content-Type: text/html; charset=UTF-8');
    !ActionView::$render && (ActionView::$render = VIEWPATH . Request::$controller . '/' . Request::$action . '.php');
} elseif (Request::$format == 'xml') {
    header('Content-type: application/rss+xml; charset=UTF-8');
    !ActionView::$render && (ActionView::$render = VIEWPATH . Request::$controller . '/' . Request::$action . '.xml.php');
}
ob_start();
# TODO: change die for a nicer way to exit.
if (!empty(ActionView::$params['render_type'])) {
    if (ActionView::$params['render_type'] == 'inline') {
        echo ActionView::$params['render_value'];
    }
} else {
    if (false === (include ActionView::$render)) {
        if (System::$conf->system_error_reporting) {
            die('Unable to find View file.');
        } else {
            exit_with_status(500);
        }
    }
}
ActionView::$content_for['layout'] = ob_get_clean();
if (Request::$format == 'html' && !empty(ActionView::$layout)) {
    if (!(include LAYOUTS . ActionView::$layout . '.php')) {
        if (System::$conf->system_error_reporting) {
            die('Unable to load Layout.');
        } else {
            exit_with_status(500);