【发布时间】:2020-06-09 09:54:35
【问题描述】:
我是 API 新手,我使用 Codeigniter 从 MySql 数据库产品创建 API 字段:金额、数量、客户姓名、客户电话、客户地址 结果看起来:
```[
{
"Id": "1",
"Amount": "21542",
"quantity": "52",
"customerName": "John",
"CustomerPhone": "254215",
"CustomerAddress": "road tvz120",
},```
但我希望它看起来像这样:
```[
{
"Id": "1",
"Amount": "21542",
"quantity": "52",
"customerInfo":{
"customerName": "John",
"CustomerPhone": "254215",
"CustomerAddress": "rue tvz120"},
},```
我的意思是将与客户相关的 3 个字段与名称客户信息进行分组
我的php代码是
```public function index_get($id = 0)
{
if(!empty($id)){
$data = $this->db->get_where("Products", ['Id' => $id])->row_array();
}else{
$data = $this->db->get("Products")->result();
}
$this->response($data, REST_Controller::HTTP_OK);
}```
【问题讨论】:
标签: php mysql api rest codeigniter