簡體   English   中英

使用symfony2創建配置

[英]Create a configuration with symfony2

我正在嘗試在Symfony上創建此配置

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()

而且我絕對不知道這個錯誤是從哪里來的:/

您沒有指定問題所在的代碼行,但是對我來說,您似乎忘記了在parameters節點定義之后調用children()方法:

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

應該是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM