在Symfony 2.7应用程序中,我们尝试设置一个humanize_bytes Twig过滤器,以便将大量字节转换为人类可读的形式--例如- 10 MB。
在我们的HumanReadableBytesExtension.php文件中有以下内容:
public function getFilters() {
return [
new TwigFilter('humanize_bytes', [$this, 'getHumanReadableBytesFilter'])
];
}..。在我们的services.yml文件中有以下内容:
mycompany.cms.twig.extension.human_readable_bytes_extension:
class: MyCompany\TwigExtensions\HumanReadableBytesExtension
arguments:
- '@translator'
tags:
- {name: twig.extension}..。但是我们发现getFilters()方法没有被调用,当我们试图调用Twig模板中的过滤器时,我们得到:
未知的"humanize_bytes“过滤器。
这两个文件都通过语法验证。缓存已被清除。还有其他地方我们应该注册这个过滤器吗?
====
编辑:这里是app/console debug:container mycompany.cms.twig.extension.human_readable_bytes_extension命令的输出:
服务mycompany.cms.twig.extension.human_readable_bytes_extension服务Id的容器信息 mycompany.cms.twig.extension.human_readable_bytes_extension类 MyCompany\TwigExtensions\HumanReadableBytesExtension标记- twig.extension ()作用域容器公共的是合成的没有延迟的没有同步的没有抽象的
发布于 2018-07-17 13:24:28
你说过你在使用抽象类。您是否在您的getName中重写了HumanReadableBytesExtension方法?
如果两个扩展名相同,则只加载一个扩展名,第二个扩展名将被忽略。
发布于 2018-07-18 13:19:29
最后,我把所有的更改都放到了一个新的特性分支上。这“解决了”了问题,尽管以一种非常不令人满意的方式。(我们从来没有真正搞清楚到底出了什么问题。)
https://stackoverflow.com/questions/51381069
复制相似问题