2016-11-16 35 views
1

我正在尋找創建樹枝的擴展,但Symfony一直告訴我我的功能未知。調用樹枝分機時未知函數錯誤

這裏是我的類:

<?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 \資源\ CONFIG \ services.yml

services: 
    app.form_extension: 
     class: AppBundle\Twig\Extension\FormExtension 
     tags: 
      - { name: twig.extension } 

我可能丟失somehing服務的聲明,但是我做不到找出什麼。請幫忙!

回答

2
  1. 正確getFonctionsgetFunctions
  2. 試試這個方法:
    ... 
        return array(
         new Twig_SimpleFunction('form_color', null, $options) 
        ); 
    ...