2013-02-27 60 views

回答

2

我找到了答案,可能对谁通过这里有用。

$output = $this->twig->render('template.html'); // use render instead of display 
$this->output->set_output($output); // use CI's output (autoloaded by default) manually 
$this->output->cache(5); // cache for 5 minutes, doesn't matter where this line is in the function. 
1

当你发现你自己,你应该通过适当的方法之一,以利用其内置的缓存功能映射输出到Output类。请注意,目前在Github上开发的CI 3.0有一些您可能会喜欢的更新(例如,保留所有输出标头的gzipped缓存文件)。

你可以用定制的view()方法延长Loader库,并有执行逻辑为好,而不是在每个控制器需要2+行(如果你想加载多个文件,你必须调用render()然后每次都是append_output())。

I did exactly that与Smarty模板库。应该能够做与Twig类似的事情。 (我一直有意将它移植过来,但还没有时间。)