有没有办法覆盖Compiler :: template()中定义的php锂缓存路径

时间:2015-11-26 15:28:44

标签: php lithium

我想知道是否可以在运行时覆盖此方法中定义的cachePath:

http://li3.me/docs/lithium/template/view/Compiler::template()

我正在尝试使用锂作为多租户应用程序,我试图在包括已编译模板的租户之间分离所有内容。

1 个答案:

答案 0 :(得分:2)

根据您的实施情况,有很多方法可以做到这一点。 一种方法是在bootstrap期间使用Media :: type函数设置html(或其他内容类型)处理程序的compiler.path参数。

例如:

Media::type('html', null, array(
  'cast' => false,
  'view' => 'lithium\template\View',
  'paths' => array(
    'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
    'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
    'element'  => '{:library}/views/elements/{:template}.{:type}.php'
  ),
  'compiler' => array(
    'path' => '/path/to/your/cache/folder'
  )
));

但根据您的要求判断,看起来您最好扩展\ lithium \ template \ view \ Compiler类并覆盖模板函数。

您可以通过使用相同的Media :: type函数

设置编译器的类名来完成此操作
Media::type('html', null, array(
  'cast' => false,
  'view' => 'lithium\template\View',
  'paths' => array(
    'template' => '{:library}/views/{:controller}/{:template}.{:type}.php',
    'layout'   => '{:library}/views/layouts/{:layout}.{:type}.php',
    'element'  => '{:library}/views/elements/{:template}.{:type}.php'
  ),
  'classes' => array(
    'compiler' => '\namespace\class\name'
  )
));
相关问题