Use case: just one action which should return a plain (text) content as-is:
public function actionAsXML()
{
$this->layout = false;
Yii::$app->response->format = Response::FORMAT_XML;
return ['aaa' => [1, 2, 3, 4]];;
}
Pre-defined response formats are:
There is no mime type for text/plain
out of the box, use this instead:
public function actionPlainText()
{
$this->layout = false;
Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', 'text/plain');
return $this->render('plain-text'); // outputs template as plain text
}