Phalcon PhP - Unknown filter

蓝咒 提交于 2019-12-24 05:45:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!