问题
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;
});
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"
.
回答1:
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;
});
来源:https://stackoverflow.com/questions/39175399/phalcon-php-unknown-filter