sam*_*les 3 php xml laravel blade laravel-4
我正在使用 Laravel 4 生成 Google 产品提要。我使用 Blade 文件来执行此操作,但 Laravel 在输出的最开始添加了一个神秘空间,这导致 Google 拒绝 XML 文件无效。任何想法为什么?
我的控制器是:
public function googleFeed()
{
//generates a Google Merchant XML feed of products
$products = DB::table('products')->get();
$content = View::make('shop.googlefeed', ['products' => $products]);
return Response::make($content, '200')->header('Content-Type', 'text/xml');
}
Run Code Online (Sandbox Code Playgroud)
还有我的刀片文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Title</title>
<link>http://example</link>
<description>Desc</description>
@foreach ($products as $product)
<item>
<g:id>{{($product->id)}}</g:id>
<title>{{($product->productname)}}</title>
<link>http://example.com/product/{{($product->slug)}}</link>
<description>{{($product->shortdesc)}}</description>
<g:image_link>{{($product->imgurlthumb)}}</g:image_link>
<g:price>{{($product->productprice)}} GBP</g:price>
<g:gtin>{{($product->gtin)}}</g:gtin>
<g:condition>new</g:condition>
<g:availability>in stock</g:availability>
</item>
@endforeach
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)
Blade 文件中没有空间。但是,输出是:
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Title</title>
....
Run Code Online (Sandbox Code Playgroud)
为什么要添加这个空间?我只是看不出它来自哪里!这似乎不是什么大问题,但它会导致提要验证失败并被 Google 拒绝。无法确定它的来源,有没有办法在处理后剥离它?
非常感谢。
当我注意到 routes.php 文件的开头有一个空格时,我解决了这个问题。删除它解决了这个问题。简单但令人沮丧,希望它可以帮助别人!(该空间可以位于大多数文件的开头。)
<?php
Route::get('/', function () {
return "Hello";
});
...
Run Code Online (Sandbox Code Playgroud)
到:
<?php
Route::get('/', function () {
return "Hello";
});
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1710 次 |
| 最近记录: |