Reputation: 181
I works in my project by LARAVEL.
I want to make sitemap. This is my controller:
class SitemapController extends BaseController {
public function index() {
header("Content-Type: text/xml;charset=utf-8");
return View::make('sitemap');
}
}
And This is my view sitemap.blade.php:
{{<?xml version="1.0" encoding="UTF-8" ?>}}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>{{url()}}</loc>
<priority>0.5</priority>
</url>
.
.
.
</urlset>
But result not appeared as XML. It appeared as a normal text.
Upvotes: 6
Views: 6154
Reputation: 5159
Add the XML declaration like this:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
Upvotes: 1
Reputation: 9275
I suggest you should use this package https://github.com/RoumenDamianoff/laravel-sitemap
Add the following to your composer.json
file :
"roumen/sitemap": "dev-master"
Then register this service provider with Laravel :
'Roumen\Sitemap\SitemapServiceProvider',
Publish configuration file. (OPTIONAL)
php artisan config:publish roumen/sitemap
Upvotes: 5
Reputation: 181
It works when I used:
{{'<?xml version="1.0" encoding="UTF-8" ?>'}}
and I updated my controller as:
class SitemapController extends BaseController {
public function index() {
$content = View::make('sitemap');
return Response::make($content)->header('Content-Type', 'text/xml;charset=utf-8');
}
}
Upvotes: 6
Reputation: 3658
Wrap the XML declaration in single quotes:
{{'<?xml version="1.0" encoding="UTF-8" ?>'}}
Works for my in Laravel.
Upvotes: 1