S
S
Sergey Pugovkin2016-10-09 15:58:46
Yii
Sergey Pugovkin, 2016-10-09 15:58:46

How to specify options for XmlResponseFormatter?

I didn't quite understand how to use XML response in Yii2.
We need to change the root tag.
www.yiiframework.com/doc-2.0/yii-web-xmlresponsefo... - how to specify this? action:

public function actionMy()
{
    Yii::$app->response->format = Response::FORMAT_XML;
    return ['...'];
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-10
@Driver86

XmlResponseFormatter settings can be specified in the application configuration, like so:

'components' => [
    'response' => [
        'formatters' => [
            'xml' => [
                'class' => '\yii\web\XmlResponseFormatter',
                'rootTag' => 'mytag'
            ]
        ],
    ],
],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question