1.方式一
model appindex ruang nama;
gunakan thinkModel;
class Classfiy memanjangkan Model{
$table yang dilindungi 'classfiy';
// 方式一
public function htmllist(){
$data=$this->select();
- return $ htmls data);
}
fungsi awam htmllistM($data,$pid=0,$lev=''){
statik $arr=array();
foreach($data sebagai $key =>$value){
if($value['pid']==$pid){
$value['lev']=$lev;
$ this- & gt; htmllistm ($ data, $ value ['id'], $ lev. '!-');
}
}
return $ ar;
// 方式二
fungsi awam getHtmlList(&$result = [], $pid = 0, $prefx = '')
{
$data = $this-()>select ;
// $data = $this->select()->toarray();//有时出错
foreach ($data sebagai $value) {
value ['pid'] == $pid) {
$value['name'] = $prefx.$value['name'];
$hasil[] $ $ $ s- >getHtmlList($result,$value['id'],$prefx.'|--');
}
}
return $result; > }
?>
{
"ret": 200,
"data": [
{
"id": 1,
"nama": "telefon bimbit",
" pid ": 0,
"statik": 1,
"masa": 1588775166,
"masa_akhir": null,
"masa_padam": null,
"lev": ""
},
"statik": 1,
"masa": 1588776159,
"masa_akhir": null,
"masa_padam": null,
"lev": "! --"
},
{
“id ": 6,
"nama": "iPhone",
"pid": 1,
"statik": 1,
"masa": 1588776200,
"masa_akhir": null,
"masa_padam": null,
"lev": "!--"
},
"id" : 2,
"nama": "Komputer ",
"pid": 0,
"statik": 0,
"masa": 1588775190,
"masa_akhir": null,
"delete_time": null,
"lev": ""
},
"id": 5,
"id": "Huawei Computer",
"pid" : 2,
"statik" ": 0,
"masa": 1588776185,
"masa_akhir": 1588816674,
"masa_padam": null,
"lev" : "!- -"
},
"id": 7,
"id": 7,
"nama": "Apple Computer",
"pid": 2,
" statik": 1,
"masa": 1588776215,
"masa_akhir": 1588816980,
"masa_padam": null,
"lev": "!--"
}
],
"msg": ""}
Format data yang dikembalikan mengikut kaedah 2 ialah
{
"ret": 200,
"data": [
{
"id": 1,
"nama": "telefon bimbit",
" pid ": 0,
"statik": 1,
"masa": 1588775166,
"masa_akhir": null,
"masa_padam": null
}, " id": 4,
"nama": "|--Telefon bimbit Huawei",
"pid": 1,
"statik": 1,
"masa": 1588776159,
"last_time": null,
"delete_time": null
},
"id": 6,
"name": "|--iPhone",
"pid": 1,
"statik": 1,
"masa": 1588776200,
"masa_akhir": null,
"masa_padam": null
},
"id": 2 ,
"nama": "komputer",
"pid": 0,
"statik": 0,
"masa": 1588775190,
"masa_akhir": null,
"delete_time": null
},
"id": 5,
"name": "|--Huawei Computer",
"pid": 2,
"statik" : 0,
"masa": 1588776185,
"masa_akhir": 1588816674,
"masa_padam": null
},
"id": 7,
"nama": "|--Apple Computer",
"pid": 2,
"statik": 1,
"masa" : 1588776215,
"last_time": 1588816980,
"delete_time" : null
}
],
"msg": ""
}
Atas ialah kandungan terperinci Pengelasan tanpa had bagi data thinkphp5. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!