本文介绍了Phalcon PhP-未知过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为货币创建自定义过滤器,以便可以在.volt模板中使用.这就是我在我的services.php中注册过滤器的方式
I'm trying to create custom filter for currency so I can use in my .volt templates. This is how I register the filter in my services.php
$di->setShared('filter', function() {
$filter = new \Phalcon\Filter();
$filter->add('currency', function ($value) {
if($value === '') {
return NULL;
} else {
return $value; // @todo implement the currency formatting
}
});
return $filter;
});
然后,当我尝试在.volt模板中使用它时,像这样{{ quote['total_fees']|currency }}
,我收到以下消息Unknown filter "currency"
.
Then when I try to use it in my .volt template, like this {{ quote['total_fees']|currency }}
I get the following message Unknown filter "currency"
.
推荐答案
我认为我已经发布了链接,但是好的,这里您又来了- https://docs.phalconphp.com/pl/latest/reference/volt.html#id2 .它应该看起来像这样:
I think i already posted link, but okay, here you go again - https://docs.phalconphp.com/pl/latest/reference/volt.html#id2. It should look like this:
$di->set('view', function() {
$view = new View();
$view->registerEngines([
'.volt' => function($view, $di) {
$volt = new Volt($view, $di);
$compiler = $volt->getCompiler();
$compiler->addFilter('currency',your code);
}
]);
return $view;
});
这篇关于Phalcon PhP-未知过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!