调用树枝扩展时未知函数错误 [英] unknow function error when calling twig extension
本文介绍了调用树枝扩展时未知函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个 twig 扩展,但 Symfony 一直告诉我我的功能未知.
I'm looking to create a twig extension but Symfony keeps telling me my function is unknown.
这是我的课:
<?php
namespace AppBundle\Twig\Extension;
use Twig_Extension;
use Twig_SimpleFunction;
class FormExtension extends Twig_Extension
{
public function getFonctions()
{
$twigClass = 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode';
$options = array(
'node_class' => $twigClass,
'is_safe' => ['html']
);
return array(
'form_color' => new Twig_SimpleFunction($this, null, $options)
);
}
public function getName()
{
return 'app_form_extension';
}
}
这里是 AppBundle\Resources\config\services.yml 中的服务声明
And here is the service declaration in AppBundle\Resources\config\services.yml
services:
app.form_extension:
class: AppBundle\Twig\Extension\FormExtension
tags:
- { name: twig.extension }
我可能遗漏了一些东西,但我不知道是什么.请帮忙!
I'm probably missing somehing but I can't find out what. Please help!
推荐答案
- 将
getFonctions
更正为getFunctions
- 试试这个:
- Correct
getFonctions
togetFunctions
- Try this way:
...
return array(
new Twig_SimpleFunction('form_color', null, $options)
);
...
这篇关于调用树枝扩展时未知函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文