twig add filter stripslashes(无框架)

时间:2015-09-22 11:49:00

标签: php twig stripslashes addslashes

在我的数据库中,我使用addslashes http://php.net/manual/fr/function.addslashes.php

来覆盖每个字符串

现在我想用striplashes“unes​​cape”我的数据,以在树枝视图中显示它们http://php.net/manual/fr/function.stripslashes.php

我没有使用框架。只有PHP MVC架构。 Twig与作曲家一起安装并且工作正常。

以下是我尝试在TWIG中实现新过滤器的方法:

require './vendor/autoload.php';

/**
 * TWIG
 */
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('vue');
$twig = new Twig_Environment($loader, array('debug' => true));
$twig->addExtension(new Twig_Extension_Debug());
$filter = new Twig_SimpleFilter('strips', function ($string) {
    return stripslashes($string);
});
$twig->addFilter($filter);

我如何尝试使用:

{{ realisation.getName | strips }}

答案是:

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The filter "strips" does not exist in "allReal.twig"

0 个答案:

没有答案