2017-06-07 20 views
0

我为API开发设置了symfony 3 apache 2.4和mysql环境...我刚开始并且index.html.twig页面出现像这样:enter image description here如何将内容类型:应用程序/ json转换为响应头中的html

和我的响应头看起来 enter image description here

我config.yml已FOSRest配置为JSON格式而不是HTML:

# FOSRest Configuration 
fos_rest: 
    body_listener: true 
    format_listener: 
     rules: 
      - { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: false } 
    param_fetcher_listener: true 
    view: 
     view_response_listener: 'force' 
     formats: 
      json: true 

# Nelmio CORS Configuration 
nelmio_cors: 
    defaults: 
     allow_credentials: false 
     allow_origin: ['*'] 
     allow_headers: ['*'] 
     allow_methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] 
     max_age: 3600 
     hosts: [] 
     origin_regex: false 

我的问题:如何才能让我的网页渲染作为HTML?

+3

只是为了笑着尝试改变路径:“^ /”到路径:“^/API” – Cerad

回答

0

在您的FOSRest配置中,您告诉他在URL匹配^/(即每个URL)时处理响应。

如果你想使用FOSRest格式的一切,但主要的页面,你可以将其配置如下:

fos_rest: 
    # ... 
    format_listener: 
      rules: 
       - { path: '^/.+', priorities: ['json'], fallback_format: json, prefer_extension: false } 
       - { path: '^/', stop: true } 
相关问题