SonataPageBundle 没有为矩阵区域“标题”定义容器

Posted

技术标签:

【中文标题】SonataPageBundle 没有为矩阵区域“标题”定义容器【英文标题】:SonataPageBundle No container defined for matrix area "header" 【发布时间】:2017-04-07 16:06:43 【问题描述】:

我已经安装了 sonatapagebundle 并生成了所有路由。 但是当我尝试配置奏鸣曲页面作曲家时,我只有错误: 没有为矩阵区域“标题”定义容器

这是可能的奏鸣曲页面配置:

sonata_page:
    multisite: host
    use_streamed_response: true # set the value to false in debug mode or if the reverse proxy does not handle streamed response
    ignore_route_patterns:
        - ^(.*)admin(.*)   # ignore admin route, ie route containing 'admin'
        - ^_(.*)          # ignore symfony routes
    ignore_routes:
        - sonata_page_cache_esi
        - sonata_page_cache_ssi
        - sonata_page_js_sync_cache
        - sonata_page_js_async_cache
        - sonata_cache_esi
        - sonata_cache_ssi
        - sonata_cache_js_async
        - sonata_cache_js_sync
        - sonata_cache_apc
    ignore_uri_patterns:
        - ^/admin\/   # ignore admin route, ie route containing 'admin'
    page_defaults:
        homepage: decorate: false # disable decoration for homepage, key - is a page route
    default_template: default # template key from templates section, used as default for pages
    templates:
        default:
            path: 'ApplicationSonataPageBundle::demo_layout.html.twig'
            name: 'default'
            containers:
                header:
                    name: Header
                content_top:
                    name: Top content
                content:
                    name: Main content
                content_bottom:
                    name: Bottom content
                footer:
                    name: Footer
            matrix:
                layout: |
                    HHHHHHHH
                    TTTTTTTT
                    TTTTTTTT
                    CCCCCCCC
                    CCCCCCCC
                    BBBBBBBB
                    BBBBBBBB
                    FFFFFFFF

                mapping:
                    H: header
                    T: content_top
                    C: content
                    B: content_bottom
                    F: footer
        2columns:
            path: 'ApplicationSonataPageBundle::demo_2columns_layout.html.twig'
            name: '2 columns layout'
            inherits_containers: default
            containers:
                left_col:
                    name: Left column
                    blocks:
                        - sonata.media.block.media
                        - sonata.media.block.gallery
                        - sonata.media.block.feature_media
                right_col:
                    name: Right column
                    blocks:
                        - sonata.news.block.recent_posts
                        - sonata.order.block.recent_orders
                        - sonata.product.block.recent_products
            matrix:
                layout: |

                    HHHHHHHHHH
                    TTTTTTTTTT
                    TTTTTTTTTT
                    LLLCCCCRRR
                    LLLCCCCRRR
                    BBBBBBBBBB
                    BBBBBBBBBB
                    FFFFFFFFFF

                mapping:
                   H: header
                   T: content_top
                   L: left_col
                   R: right_col
                   C: content
                   B: content_bottom
                   F: footer

    # manage the http errors
    catch_exceptions:
        not_found: [404]    # render 404 page with "not_found" key (name generated: _page_internal_error_key)
        fatal:     [500]    # so you can use the same page for different http errors or specify specific page for each error

有什么想法吗? 问候

【问题讨论】:

可能是因为默认部分HHHHHHHH第一行前漏了一个空行 No :( 这无济于事仍然有这个错误。 【参考方案1】:

好的,我资助出了什么问题。这是正确的配置:

sonata_page:
    multisite:             host # host
    use_streamed_response: false # set the value to false in debug mode or if the reverse proxy does not handle streamed response

    ignore_uri_patterns:
        - ^/admin(.*)
        - ^/api/(.*)

    ignore_route_patterns:
        - (.*)admin(.*)     # ignore admin route, ie route containing 'admin'
        - ^_(.*)            # ignore symfony routes

    ignore_routes:
        - sonata_page_cache_esi
        - sonata_page_cache_ssi
        - sonata_page_js_sync_cache
        - sonata_page_js_async_cache
        - sonata_cache_esi
        - sonata_cache_ssi
        - sonata_cache_js_async
        - sonata_cache_js_sync
        - sonata_cache_apc

    cache_invalidation:
        service:  sonata.page.cache.invalidation.simple
        recorder: sonata.page.cache.recorder
        classes:
            "Application\Sonata\PageBundle\Entity\Block": getId

    default_template: default
    templates:
        default:
          path: 'ApplicationSonataPageBundle::demo_layout.html.twig'
          name: 'default'
          containers:
             header:
                 name: Header
             content_top:
                 name: Top content
             content:
                 name: Main content
             content_bottom:
                 name: Bottom content
             footer:
                 name: Footer

          matrix:
             layout: |

                 HHHHHHHH
                 TTTTBBBB
                 TTTTBBBB
                 TTTTBBBB
                 TTTTBBBB
                 CCCCCCCC
                 CCCCCCCC
                 FFFFFFFF

             mapping:
                 H: header
                 T: content_top
                 C: content
                 B: content_bottom
                 F: footer

        2columns:  path: 'ApplicationSonataPageBundle::demo_2columns_layout.html.twig', name: '2 columns layout' 

    page_defaults:
        homepage:  decorate: false, enabled: true 

【讨论】:

更准确地说,当您关注此doc 时会出现问题,它是解决问题的本节的替换:2columns 例如:``` 2columns: path: 'ApplicationSonataPageBundle:: demo_2columns_layout.html.twig',名称:'2列布局'```

以上是关于SonataPageBundle 没有为矩阵区域“标题”定义容器的主要内容,如果未能解决你的问题,请参考以下文章

Symfony 3 - 模板“SonataPageBundle::base_error.html.twig”上的块“标题”不存在

网格/格子/椭圆区域的矩阵

304. 二维区域和检索 - 矩阵不可变

力扣304(java)-二维区域和检索-矩阵不可变(中等)

LeetCode 0304. 二维区域和检索 - 矩阵不可变

304. 二维区域和检索 - 矩阵不可变(动态规划)