|
新手上路

- 积分
- 27
- 威望
- 2
- CI版本
- 1.5.4
|
楼主
大 中
小 发表于 2008-4-17 13:16 只看该作者
Shadowhand的page_cache_hook例子
Shadowhand老大只放了个视频( http://kohanaphp.com/video/page_cache_hook.mov )没有贴代码,我把代码贴在这里,供大家参考 复制内容到剪贴板PHP 代码:class hook_page_cache { private $cache; public function __construct () { $this-> cache = new Cache (); Event:: add_before('system.routing', array('Router', 'setup'), array($this, 'load_cache')); } public function load_cache () { $uri = Router:current_uri; if(empty($uri)) { $uri = 'welcome'; } if ($page = $this-> cache-> get('page_'. $uri)) { Kohana:: render($page); exit(); } else { Event:: add('system.display', array($this, 'save_cache')); } } public function save_cache () { $this-> cache-> set('page_'.Router:: $current_uri, Event:: $data); }}$hook = new hook_page_cache (); unset($hook); [ 本帖最后由 number5 于 2008-4-17 13:18 编辑 ]
|