Вопрос

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.

Это было полезно?

Решение

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');
        }
}

Другие советы

I suggest you should use this package https://github.com/RoumenDamianoff/laravel-sitemap

Installation

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

Wrap the XML declaration in single quotes:

{{'<?xml version="1.0" encoding="UTF-8" ?>'}}

Works for my in Laravel.

Add the XML declaration like this:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top