Exemplo n.º 1
0
 function display($template = null, $cache_id = null, $complile_id = null)
 {
     if ($template == null) {
         global $php;
         $template = $php->env['mvc']['controller'] . '_' . $php->env['mvc']['view'] . '.html';
     }
     if ($this->if_pagecache) {
         $pagecache = new Swoole_pageCache($this->cache_life);
         if (!$pagecache->isCached()) {
             $pagecache->create(parent::fetch($template, $cache_id, $complile_id));
         }
         $pagecache->load();
     } else {
         parent::display($template, $cache_id, $complile_id);
     }
 }
Exemplo n.º 2
0
 function runView($pagecache = false)
 {
     if ($pagecache) {
         //echo '启用缓存';
         $cache = new Swoole_pageCache(3600);
         if ($cache->isCached()) {
             //echo '调用缓存';
             $cache->load();
         } else {
             //echo '没有缓存,正在建立缓存';
             $view = isset($_GET['view']) ? $_GET['view'] : 'index';
             if (!preg_match('/^[a-z0-9_]+$/i', $view)) {
                 return false;
             }
             foreach ($_GET as $key => $param) {
                 $this->tpl->assign($key, $param);
             }
             $cache->create($this->tpl->fetch($view . '.html'));
             $this->tpl->display($view . '.html');
         }
     } else {
         //echo '不启用缓存';
         $view = isset($_GET['view']) ? $_GET['view'] : 'index';
         foreach ($_GET as $key => $param) {
             $this->tpl->assign($key, $param);
         }
         $this->tpl->display($view . '.html');
     }
 }
Exemplo n.º 3
0
 /**
 +----------------------------------------------------------
 * 输出模板
 +----------------------------------------------------------
 * @access protected
 +----------------------------------------------------------
 * @param string $content 模板内容
 * @param boolean $display 是否直接显示
 +----------------------------------------------------------
 * @return mixed
 +----------------------------------------------------------
 */
 protected function output($content, $display)
 {
     if ($this->if_pagecache) {
         $pagecache = new Swoole_pageCache($this->cache_life);
         if ($pagecache->isCached()) {
             $pagecache->load();
         } else {
             $pagecache->create($content);
         }
     }
     if ($display) {
         $showTime = $this->showTime();
         echo $content;
         if ($this->show_runtime) {
             $this->showTrace();
         }
         return null;
     } else {
         return $content;
     }
 }