使用laravel渲染站點地圖時出現問題。 生成的XML似乎確定,但是當我嘗試從Chrome或Firefox調用的URL,我得到一個錯誤使用laravel渲染站點地圖時出現錯誤
error on line 2 at column 6: XML declaration allowed only at the start of the document
事實上該文件的第一行是空的,XML聲明第2行開始
這裏我的代碼:
return Response::view('sitemap.index', ['agences' => $agences])->header('Content-Type', 'application/xml');
我想,語法太:
$xml = View::make('sitemap.index', ['agences' => $agences]);
return Response::make($xml, 200)->header('Content-Type', 'application/xml');
這樣我可以做
dd($xml->render());
並且實現返回的字符串沒有空的第一行。 所以我猜測迴應::使責怪,但我真的不知道從哪裏看
我想你已經在文檔的開始時檢查了空白嗎? – Adrenaxus 2014-11-25 09:40:08
嗨Adrenaxus,我甚至三重檢查它..... – elfif 2014-11-25 09:41:10
嘗試設置''Content-Type','text/xml'' – Adrenaxus 2014-11-25 09:54:01