2017-06-07 27 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 } 
相關問題