Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony将树枝文件解析为xml而不是html_Php_Xml_Twig_Symfony4 - Fatal编程技术网

Php Symfony将树枝文件解析为xml而不是html

Php Symfony将树枝文件解析为xml而不是html,php,xml,twig,symfony4,Php,Xml,Twig,Symfony4,不管什么原因。我的小树枝文件现在被读取为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="

不管什么原因。我的小树枝文件现在被读取为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">
...
/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 }

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

config/packages/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
# 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 ] }

为我们提供配置…哪些?我有20个。twig(可能是framework.yaml)的配置可以查看fos rest配置。您使用站点上的每个页面作为RESTAPI(路径:^/)。您应该更改路径以仅为您的api路由提供服务(例如,在它们前面加上/api/v1/…看起来问题确实出在fos_rest.yaml中。我在休息时使用的是FOSRestBundle,而Symfony上的文档不幸已过时。