【问题标题】:Is there a way to override the php lithium cache path defined in Compiler::template()有没有办法覆盖 Compiler::template() 中定义的 php 锂缓存路径
【发布时间】:2015-11-26 15:28:44
【问题描述】:

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

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

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

【问题讨论】:

  • 如果在应该使用的选项中定义了“路径”,而不是默认值。如果您在第 3 行看到 $options += $defaults;它添加了不存在的参数,但如果它们存在,它不会覆盖它们。所以如果你将路径设置为方法的选项数组,它会很好..
  • 是的,我注意到@svetlio,但我使用 xdebug 对一个请求进行了完整的查找,我知道在哪里调用了 compile::template() 但有很多间接调用,我不确定我应该在哪里设置选项而不实际修改锂核心。
  • 请张贴您已编写但无法运行或您想编写的代码的 sn-p

标签: php lithium


【解决方案1】:

有很多方法可以做到这一点,具体取决于您的实施。 一种方法是在引导期间使用 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'
  )
));

【讨论】:

    猜你喜欢
    • 2016-05-18
    • 1970-01-01
    • 2012-07-07
    • 2018-03-31
    • 2013-09-11
    • 2017-05-16
    • 2011-04-15
    • 2018-10-05
    • 1970-01-01
    相关资源
    最近更新 更多