php - Add attributes to XML tags in Yii 2 Response -
yii2. action (method) in controller:
public function actionget() { yii::$app->response->format = response::format_xml; return [ 'items' => [ ['id' => 'data'], ['id' => 'body'], ], ]; }
at output xml:
<?xml version="1.0" encoding="utf-8"?> <response> <items> <item> <id>data</id> </item> <item> <id>body</id> </item> </items> </response>
how can add attributes in xml tags? , remove response
tag:
<?xml version="1.0" encoding="utf-8"?> <items> <item update="true"> <id>data</id> </item> <item update="false" new="true"> <id>body</id> </item> </items>
documentation not show case.
you can't.
this feature not supported , isn't on roadmap. you'll have build own responseformatter (implementing http://www.yiiframework.com/doc-2.0/yii-web-responseformatterinterface.html) achieve this.
see: https://github.com/yiisoft/yii2/issues/5996
also, removing response
tag isn't possible. can rename root tag setting roottag
value formatter. http://www.yiiframework.com/doc-2.0/yii-web-xmlresponseformatter.html#%24roottag-detail
Comments
Post a Comment