bobchengbin/yii2-xml-request-parser

此包已被弃用且不再维护。未建议替代包。

Yii2 xml 请求解析器

v0.0.2 2015-08-28 15:40 UTC

This package is not auto-updated.

Last update: 2020-01-20 17:28:45 UTC


README

Yii2 官方只提供了JsonRequestParser,但没有 XmlRequestParser,因此创建了这样一个库。

安装

在 composer.json 的 require 部分添加 "bobchengbin/yii2-xml-request-parser": "*"

$ composer update

或者

$ composer require bobchengbin/yii2-xml-request-parser '*'

使用

# file app/config/main.php
<?php

return [
    'components' => [
	'request' => [
	    'parsers' => [
                'application/xml' => [
		    'class' => 'bobchengbin\Yii2XmlRequestParser\XmlRequestParser',
		    'priority' => 'tag', // the default value is 'tag', you can set 'attribute' value
		],
	    ],
        ],
    ],
];

最终测试

然后你可以使用 Postman 等工具向你的应用发送一个 XML 请求,然后应用可以直接通过 Yii::$app->request->post() 获取数据。