Answer the question
In order to leave comments, you need to log in
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]);
<?='<?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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question