00001 <?php 00022 class View 00023 { 00029 protected static $_content = ''; 00036 public static function render($controller, $_url) 00037 { 00041 require CORE_PATH . 'helpers/tags.php'; 00042 00047 extract(get_object_vars($controller), EXTR_OVERWRITE); 00048 00052 self::$_content = $cache['type']=='view' ? Cache::get($_url, 'kumbia.views') : ''; 00053 if(!self::$_content) { 00058 self::$_content = ob_get_clean(); 00059 00060 if ($module_name){ 00061 $controller_views_dir = APP_PATH . "views/$module_name/$controller_name"; 00062 } else { 00063 $controller_views_dir = APP_PATH . "views/$controller_name"; 00064 } 00065 00070 if($view) { 00071 ob_start(); 00072 include "$controller_views_dir/$view.phtml"; 00073 00074 if($cache['type'] == 'view') { 00075 Cache::save(ob_get_contents(), $cache['time'], $_url, 'kumbia.views'); 00076 } 00077 00082 if($response == 'view' || $response == 'xml') { 00083 ob_end_flush(); 00084 return; 00085 } 00086 00087 self::$_content = ob_get_clean(); 00088 } 00089 } 00090 00095 if($template) { 00096 $template = APP_PATH . "views/templates/$controller->template.phtml"; 00097 } else { 00098 $template = APP_PATH . "views/templates/$controller_name.phtml"; 00099 } 00100 00101 if(is_file($template)) { 00102 ob_start(); 00103 include $template; 00104 00105 if($cache['type'] == 'template') { 00106 Cache::save(ob_get_contents(), $cache['time'], $_url, 'kumbia.templates'); 00107 } 00108 ob_end_flush(); 00109 return; 00110 } 00111 echo self::$_content; 00112 } 00117 public static function content() 00118 { 00119 echo self::$_content; 00120 } 00130 public static function partial($partial, $time=false, $params=array()) 00131 { 00132 if($time!==false) { 00133 if($data = Cache::start($time, $partial, 'kumbia.partials')) { 00134 echo $data; 00135 return; 00136 } 00137 } 00138 00139 if(is_string($params)) { 00140 $params = Util::get_params($params); 00141 } 00142 extract ($params); 00143 00144 $partial_file = APP_PATH . "views/partials/$partial.phtml"; 00145 00146 if(is_file($partial_file)){ 00147 include $partial_file; 00148 if($time!==false) { 00149 Cache::end(); 00150 } 00151 } else { 00152 if($time!==false) { 00153 Cache::end(false); 00154 } 00155 throw new KumbiaException('Kumbia no puede encontrar la vista parcial: "'.$partial_file.'"', 0); 00156 } 00157 } 00158 }