代码之家  ›  专栏  ›  技术社区  ›  rmsluimers

symfony将twig文件解析为XML而不是HTML

  •  0
  • rmsluimers  · 技术社区  · 6 年前

    不管什么原因。我的twig文件现在被读取为XML文件,因此我会得到XML错误。

    我翻译了第一句话。

    This XML-file does not look like it has associated style information.
    The document structure is displayed below.
    
    <html>
    <head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>     
    <title>My App</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css"/>
    ...
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"/>
    ...
    </head>
    <body>
    <div class="navbar navbar-default navbar-fixed-top">
    ...
    

    [更新]

    我被要求提供配置,所以我将提供其中包含“xml”的任何配置。

    配置/包/fos_rest.yaml

    # Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
    fos_rest:
        routing_loader:
                include_format: true
        format_listener:
            rules:
                - { path: ^/, prefer_extension: true, fallback_format: json, priorities: [ xml, json ] }
        view:
            view_response_listener:
                enabled: true
                force: true
    

    /配置/包/framework.yaml

    framework:
        secret: '%env(APP_SECRET)%'
        translator: { fallbacks: ["%locale%"] }
        #default_locale: en
        #csrf_protection: true
        #http_method_override: true
    
        # Enables session support. Note that the session will ONLY be started if you read or write from it.
        # Remove or comment this section to explicitly disable session support.
        session:
            handler_id: ~
    
        #esi: true
        #fragments: true
        php_errors:
            log: true
    
        cache:
            # Put the unique name of your app here: the prefix seed
            # is used to compute stable namespaces for cache keys.
            #prefix_seed: your_vendor_name/app_name
    
            # The app cache caches to the filesystem by default.
            # Other options include:
    
            # Redis
            #app: cache.adapter.redis
            #default_redis_provider: redis://localhost
    
            # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues)
            #app: cache.adapter.apcu
    
        templating:
            { engines: ['twig'] }
    
    sensio_framework_extra:
        view:  
            { annotations: true }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   rmsluimers    6 年前

    fosrestbundle对我来说是新的,他们还没有将文档更新到symfony 4。我也不知道tilde代表默认配置,而不是没有配置。

    配置/包/fos_rest.yaml

    # Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
    fos_rest: ~
    #    param_fetcher_listener:  true
    #    allowed_methods_listener:  true
    #    routing_loader: true
    #    view:
    #        view_response_listener:  true
    #    exception:
    #        codes:
    #            App\Exception\MyException: 403
    #        messages:
    #            App\Exception\MyException: Forbidden area.
    #    format_listener:
    #        rules:
    #            - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] }