Php 当I{{render}一个控制器时,无法使用细枝扩展
在我的模板中,我呈现以下控制器:Php 当I{{render}一个控制器时,无法使用细枝扩展,php,symfony,twig,symfony-3.3,Php,Symfony,Twig,Symfony 3.3,在我的模板中,我呈现以下控制器: {{render(controller('AppBundle:Widgets:myWidget'))} 按照约定,WidgetsController具有以下功能: 名称空间AppBundle\Controller; 使用AppBundle\Constants\WidgetsConstants; 使用AppBundle\Managers\DataFetch\WidgetsFetchingStrategy; 使用Symfony\Bundle\FrameworkBu
{{render(controller('AppBundle:Widgets:myWidget'))}
按照约定,WidgetsController
具有以下功能:
名称空间AppBundle\Controller;
使用AppBundle\Constants\WidgetsConstants;
使用AppBundle\Managers\DataFetch\WidgetsFetchingStrategy;
使用Symfony\Bundle\FrameworkBundle\Controller\Controller;
类WidgetsController扩展控制器
{
公共函数myWidgetAction(){
返回$this->render('widgets/myWidget.html.twig'[
“图像”=>[
'http://example.com/myarticle'
'http://example.org/harem',
'http://example.org/tentacle',
],
]);
}
}
而myWidget.html.twig
具有以下功能:
{%用于键,url中的url%}
{%endfor%}
而censor
是通过以下小树枝插件定义的:
namespace AppBundle\Twig;
class SanitizeArticlePhotosForList extends \Twig_Extension
{
public function getFilters()
{
return array(
new \Twig_SimpleFilter('censor', array($this, 'sensorAction')),
);
}
public function sensorAction($photoHtmlTag)
{
return str_replace(['tentacle','harem'],'censored',$photoHtmlTag);
}
}
但是我得到了以下Twig\u Error\u语法Error:
Unknown "censor" function.
你们知道为什么吗?通过my services.php,我有以下设置:
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
// To use as default template
$definition = new Definition();
$definition
->setAutowired(true)
->setAutoconfigured(true)
->setPublic(false);
$this->registerClasses($definition, 'AppBundle\\', '../../src/AppBundle/*', '../../src/AppBundle/{Entity,Repository,Resources,Tests}');
// Changes default config
$definition->setPublic(true)->addTag('controller.service_arguments');
// $this is a reference to the current loader
//Loafing Controllers
$this->registerClasses($definition, 'AppBundle\\Controller\\', '../../src/AppBundle/Controller/*');
$this->registerClasses($definition, 'AppBundle\\Twig\\', '../../src/AppBundle/Twig/*');
伙计们,你们知道为什么吗?请试着这样呼叫分机
{{url}审查}
也许可以为解决方案提供更多内容:您的扩展定义了一个过滤器,而不是一个函数。这些在细枝上是不同的东西。