默認返回JSON數(shù)據(jù)格式參數(shù)為:msg、code、total、id、return等等
開發(fā)者可以在URL參數(shù)中加上&function=dr_function_test
這時候返回數(shù)據(jù)格式就會采用自定義換上dr_function_test來做轉換
實例接口URL
/index.php?c=api&m=data2&auth=472869ef85d15227acb937eac8d89243&function=dr_function_test
舉例說明:
假設你查詢新聞列表數(shù)據(jù),需要返回會員的頭像(默認是返回uid參數(shù)),可以這樣自定義返回結果:
第一步:請求地址
/index.php?c=api&m=data2&auth=472869ef85d15227acb937eac8d89243&function=dr_function_test¶m=list action=module module=news num=10
第二步:定義函數(shù)
新在config/costom.php文件中定義上面的函數(shù)dr_function_test
function dr_function_test($data) { if ($data['return']) { $now = array(); foreach ($data['return'] as $t) { $t['touxiang'] = dr_avatar($t['uid']); $now[] = $t; } $data['return'] = $now; } return $data; }
這時候就會返回你自己的數(shù)據(jù)格式了
相關回調技巧
function dr_function_test($data) { if ($data['return']) { $now = array(); foreach ($data['return'] as $t) { // 文件或圖片完整地址 $t['圖片字段'] = dr_get_file($t['圖片字段']); // 聯(lián)動菜單的地址詳情 $linkage = dr_linkage('address', $t[地址字段]); $t['地址字段'] = $linkage[name]; $now[] = $t; } $data['return'] = $now; } return $data; }
文檔最后更新時間:2019-04-15 16:35:28