Symfony将twig文件解析为xml而不是html

时间:2018-05-24 08:37:41

标签: php xml twig symfony4

无论出于何种原因。我的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

/config/packages/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 个答案:

答案 0 :(得分:0)

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

配置/包/ 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 ] }