Answer the question
In order to leave comments, you need to log in
If there is a rule in urlManager headers->set doesn't work?
I'm making a sitemap controller.
The idea is this: if you turn to / sitemap - sitemapindex is issued.
If you turn to /sitemap/type.xml - a urlset is issued.
For this, I registered in the config:
'urlManager' => [
...
'rules' => [
'/sitemap/<file>' => 'sitemap/index',
....
]
public function actionIndex( $file = 0 )
{
// Заголовок Content-Type XML
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->set('Content-Type', 'text/xml');
if(!$file) {
// Здесь вывожу sitemapindex;
return;
}
// Здесь вывожу urlset для нужного $file
}
Answer the question
In order to leave comments, you need to log in
I think that
$headers = Yii::$app->response->headers;
$headers->set('Content-Type', 'text/xml');
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'text/xml');
Interesting... on /sitemap/xxxxxx (the URL is processed through urlmanager and sent to the sitemap controller) - it works simply:
but if we directly access the /sitemap controller,
then it only works like this:
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'text/xml');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question