1. 在模块配置中, 写入, 这样的话, 整个模块都返回json, 适用用接口类.
<?php
// +----------------------------------------------------------------------
// | User: zq
// +----------------------------------------------------------------------
// | Time: 2019-06-17 09:54
// +----------------------------------------------------------------------
return [
// 默认输出类型
'default_return_type' => 'json',
];
2. 在方法中, 动态配置.
public function getUserInfo($type = 'json')
{
if (!in_array($type, ['json', 'xml'])) {
$type = 'json';
}
Config::set('default_return_type', $type);
$data = [
'code' => 200,
'result' => [
'username' => 'zq',
'useremail' => '111@qq.com',
]
];
return $data;
}