예제 #1
0
 function render($view_name)
 {
     $path = __SITE_PATH . '/content/views/' . $view_name . '.php';
     if (file_exists($path) === false || is_readable($path) === false) {
         throw new Exception('View Not Found In ' . $path);
         return false;
     }
     // set view path
     ezphp::ez_set('ez_view_path', dirname($path) . '/');
     $this->view_path = dirname($path) . '/';
     $this->vars['ez_view_path'] = dirname($path) . '/';
     # load variables to views from controller
     extract($this->vars);
     // for cache
     $qstring = $_SERVER['QUERY_STRING'];
     $qstring = preg_replace("/[^a-zA-Z0-9_]+/", '_', $qstring);
     # cache the current file
     //if (__ENABLE_CACHE == '1' && !$this->cache->isCached($view_name . $qstring))
     if (__ENABLE_CACHE == '1') {
         $cache_data = $this->getContent($path);
         $this->cache->set($view_name . $qstring, $cache_data);
         $file = glob(__SITE_PATH . '/cache/' . 'cache.' . $view_name . $qstring . '.*');
     }
     if ($this->no_template == true || ezphp::ez_get('use_template') == '0') {
         $ez_layout_content = '';
         if (__ENABLE_CACHE == '1') {
             if ($file[0]) {
                 $handle = fopen($file[0], 'r') or die('Could not open the file: ' . $file[0]);
                 $cache = fread($handle, filesize($file[0]));
                 fclose($handle);
                 print unserialize($cache);
             }
         } else {
             include $path;
         }
         if (!file_exists($file[0]) || !is_readable($file[0]) || empty($cache)) {
             include $path;
         }
     } else {
         if (__ENABLE_CACHE == '1') {
             $ez_layout_content = $this->cache->get($view_name . $qstring);
         } else {
             $ez_layout_content = $this->getContent($path);
         }
         if (empty($ez_layout_content)) {
             $ez_layout_content = $this->getContent($path);
         }
         // load the template file
         include_once __SITE_PATH . '/template/' . ezphp::get_template() . '/template.php';
     }
 }