返回值类型,是指在API接口中,输出返回值的数据结构,Restful组件支持json
和xml
两种类型,默认使用json
。
若需要修改默认的数据类型,可以修改/restful/config.php
文件中的type
配置项即可。
也可以在调用时,通过\x\Restful::type('json')
方法,临时修改。
依赖类:\x\Restful
方法名:type()
参数:
string $type
json
返回值:\x\Restful
对象本身
示例代码:
namespace app\http;
use x\controller\Http;
/**
* @Controller(prefix="")
*/
class Index extends Http
{
/**
* @RequestMapping(route="/", method="get", title="主页")
*/
public function index() {
// 使用XML返回结构
return \x\Restful::type('xml')->callback();
}
}