我有一个基于silex的站点的分支扩展:
<?php
namespace UT'Provider;
/**
* Twig extension for containing any additional twig functions we need
*/
class TwigUTProvider extends 'Twig_Extension {
public function getName() {
return 'ut_functions';
}
public function getFunctions() {
return [
new 'Twig_SimpleFunction("maybeDecodeJapanse", [$this, 'UT'Provider'TwigUTProvider::maybeDecodeJapanse()]),
];
}
public function maybeDecodeJapanse() {
return 'a string';
}
}
它在应用程序文件中注册如下:
$this->register(new Provider'TwigServiceProvider, [
'twig.path' => [
__DIR__ . '/Resources/Templates',
$this['docroot'] . '/silex/vendor/braincrafted/bootstrap-bundle/Braincrafted/Bundle/BootstrapBundle/Resources/views/Form',
__DIR__ . '/../Floso/Templates',
],
'twig.options' => [
'auto_reload' => true,
'cache' => $this['debug_mode'] ? false : ($this['docroot'] . '/silex/var/cache/twig'),
'debug' => $this['debug_mode'],
],
]);
# Add Twig extensions
$this['twig'] = $this->share($this->extend('twig', function ($twig) {
$twig->addExtension(new 'UT'Provider'TwigUTProvider());
$twig->addExtension(new BootstrapBundle'Twig'BootstrapIconExtension('glyphicon'));
$twig->addExtension(new BootstrapBundle'Twig'BootstrapLabelExtension);
$twig->addExtension(new BootstrapBundle'Twig'BootstrapBadgeExtension);
$twig->addExtension(new BootstrapBundle'Twig'BootstrapFormExtension);
$twig->addExtension(new 'Twig_Extension_StringLoader());
$twig->getExtension('core')->setTimezone('Europe/London');
return $twig;
}));
这似乎是正确的——在扩展类名中引入拼写错误会导致与我所遇到的异常不同的异常。
我用{{ maybeDecodeJapanese() }}
在我的trick模板中调用了这个扩展,这导致了这个异常(它似乎不是由模板调用本身引起的,拼写错误会生成一个标准函数未找到的异常):
Class '__TwigTemplate_3318c38dfd9c3eb0c4193184a517ff94fdd975ffb45d7f0a8f7490718f3bc1ef' not found
这发生在/silex/vendor/tritch/tritch/lib/twig/Environment.php 中
我最好的猜测是这是某种缓存文件。缓存在开发环境中是禁用的,但我已经尝试删除缓存文件夹的内容,但这并没有帮助。谷歌搜索尚未提供任何其他线索。
找到问题根源的任何帮助都将非常有帮助。
我认为函数定义中存在错误。尝试将其更改为:
...new 'Twig_SimpleFunction("maybeDecodeJapanse", [$this, "maybeDecodeJapanse"]),...