I
I
IvanMogilev2020-10-05 16:52:54
Yii
IvanMogilev, 2020-10-05 16:52:54

Sitemap.xml how to make a controller?

hello in controller

Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
        Yii::$app->response->headers->add('Content-Type', 'text/xml');
        return $this->renderPartial('sitemap',['data'=>$data]);

view
<?='<?xml version="1.0" encoding="UTF-8"?>';?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <?php
    foreach ($data as $item)
    {
        ?>
        <url>
            <loc><?=$item['url'];?></loc>
            <lastmod><?=date('Y-m-d',$item['lastmod']);?></lastmod>
            <changefreq><?=$item['changefreq'];?></changefreq>
            <priority><?=$item['priority'];?></priority>
        </url>
        <?php
    }
    ?>
</urlset>


How can I make it return the sitemap.xml url? in the config I write "sitemap.xml" => "site/sitemap", gives 404, just sitemap works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LaraLover, 2020-10-05
@IvanMogilev

Add a suffix to the urlManager for the route https://www.yiiframework.com/doc/guide/2.0/en/runt...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question