コード例 #1
0
 /**
  * Render the given action and put it in the body variable to print out later
  * @param obj $action
  */
 public static function renderToBody($action)
 {
     if (Fabriq::render() == 'none') {
         return;
     }
     ob_start();
     switch ($action->type) {
         case "module":
             $custom = "app/views/modules/{$action->controller}/{$action->action}.view.php";
             $module = "modules/{$action->controller}/views/{$action->action}.view.php";
             if (file_exists('sites/' . FabriqStack::site() . "/{$custom}")) {
                 $file = 'sites/' . FabriqStack::site() . "/{$custom}";
             } else {
                 if (file_exists($custom)) {
                     $file = $custom;
                 } else {
                     if (file_exists('sites/' . FabriqStack::site() . "/{$module}")) {
                         $file = 'sites/' . FabriqStack::site() . "/{$module}";
                     } else {
                         if (file_exists($module)) {
                             $file = $module;
                         } else {
                             throw new Exception("View for {$action->controller}'s {$action->action} action does not exist");
                         }
                     }
                 }
             }
             extract(FabriqModules::get_vars($action->controller));
             require $file;
             break;
         case "controller":
         default:
             extract(self::$tplvars);
             $view = "app/views/{$action->controller}/{$action->action}.view.php";
             if (!file_exists($view) && !file_exists('sites/' . FabriqStack::site() . "/{$view}")) {
                 FabriqStack::error(404);
             } else {
                 if (file_exists('sites/' . FabriqStack::site() . "/{$view}")) {
                     require_once 'sites/' . FabriqStack::site() . "/{$view}";
                 } else {
                     require_once $view;
                 }
             }
             break;
     }
     self::$body .= ob_get_contents();
     ob_end_clean();
 }