2017-05-29 65 views
0

我想上的Symfony創建的Symfony2

創建該配置
media: 
    medias: 
     category.type.subtype: 
      reference : "UUID" # What is used to identify object in DB (needed) 
      service : ~ # Service name "bundle.service.name" 

      identifiers: # If empty, no generator can be created for this media 
       channelId: # Example 
        label: ~ # Label for front 
        key: "channel_id" # Identifier in bdd (default : the name of identifier) 
       channelTitle: ~ 
       # Other identifier.... 

      api: # Api configuration (can be null if no API) 
       consumer_key: ~ 
       consumer_secret: ~ 
       # Others parameters... 

      parameters: 
       label: "Media 1" # Label in the front Default : generated with the name 
       page: 
        factor: 50 # Factor (default 20) 
        styles: 
         style1: 
          css_class: class1 
         style2: 
          css_class: class2 
         # Other styles... 
     category.type.subtype2: #parameters..... 

我寫這段代碼的配置:

$rootNode = $treeBuilder->root('media'); 

    $rootNode 
     ->children() 
      ->arrayNode("medias") 
       ->prototype('array') 
        ->children() 
         ->scalarNode('reference') 
          ->isRequired() 
         ->end() 

         ->scalarNode('service')->end() 

         ->arrayNode("identifiers") 
          ->prototype('array') 
           ->children() 
            ->scalarNode("label")->end() 
            ->scalarNode("key")->end() 
           ->end() 
          ->end() 
         ->end() 

         ->arrayNode("api") 
          ->prototype('scalar')->end() 
         ->end() 

         ->arrayNode("parameters") 
          ->scalarNode("label")->end() 

          ->arrayNode("page") 
           ->children() 
            ->integerNode("factor")->end() 

            ->arrayNode("styles") 
             ->prototype('array') 
              ->children() 
               ->scalarNode("css_class")->end() 
              ->end() 
             ->end() 
            ->end() 

           ->end() 
          ->end() 

         ->end() 

        ->end() 
       ->end() 
      ->end() 
     ->end() 
    ; 

但我已經錯誤:

調用未定義的方法Symfony \ Component \ Config \ Definition \ Builder \ ArrayNodeDefinition :: scalarNode()

而且我是絕對已經不知道哪裏來此錯誤:/

+0

哪條線的問題?您已從錯誤中移除該信息。 –

+0

CLI並未指示我行:/ – graille

回答

1

你沒有指定哪一行代碼是問題,但對我來說,它看起來像你忘了後parameters節點調用children()方法定義:

->arrayNode("parameters") 
    ->scalarNode("label")->end() 

它應該是這樣的:

->arrayNode("parameters") 
    ->children() 
     ->scalarNode("label")->end() 
     // other nodes 
    ->end() 
+0

我很蠢......非常感謝! :) – graille