1.方式一
espace de noms appindexmodel;
utiliser thinkModel;
class Classfiy étend le modèle{
protected $table = 'classfiy';
// 方式一
public function htmllist (){
$ data=$this->select();
return $this->htmllistM($data);
}
public function htmllistM($data,$pid=0,$lev=''){
static $ arr=array();
foreach($data as $key=>$value){
if($value['pid']==$pid){
$value['lev']=$lev;
$arr[]=$value;
$this->htmllistM($data,$value['id'],$lev.'!--');
}
}
return $arr;
}
/ / 方式二
public function getHtmlList(&$result = [], $pid = 0, $prefx = '')
{
$data = $this->select();
// $data = $this- >select()->toarray();//有时出错
foreach ($data as $value) {
if ($value['pid'] == $pid) {
$value['name' ] = $prefx.$value['name'];
$result[] = $value;
$this->getHtmlList($result,$value['id'],$prefx.'|--') ;
}
}
return $result;
}
}
?>
方式一返回的数据形式是
{
"ret": 200,
"data": [
{
"id": 1,
"name": "手机",
"pid": 0,
"statique": 1,
"heure ": 1588775166,
"last_time": null,
"delete_time": null,
"lev": ""
},
{
"id": 4,
"name": "华为手机",
"pid ": 1,
"static": 1,
"time": 1588776159,
"last_time": null,
"delete_time": null,
"lev ": "!--"
},
{
"id ": 6,
"name": "苹果手机",
"pid": 1,
"static": 1,
"time": 1588776200,
"last_time": null,
"delete_time": null,
"lev": "!--"
},
{
"id": 2,
"name": "电脑",
"pid": 0,
" statique": 0,
"heure": 1588775190 ,
"last_time": null,
"delete_time": null,
"lev": ""
,
{
"id": 5,🜜 "name": "华为电脑",
"pid": 2 ,
"static": 0,
"time": 1588776185,
"last_time": 1588816674,
"delete_time": null,
"lev": "!--"
},
{
"id": 7 ,
"name": "苹果电脑",
"pid": 2,
"static": 1,
"last_time": 1588816980,
"delete_time": null,
"lev" : "!--"
}
],
"msg": ""}
方式二返回的数据 格式是
{
"ret": 200,
"data": [
" " {
" "id": 1,
"name": "téléphone portable",
"pid": 0,
"static": 1 ,
"time" ": 1588775166,
" "last_time": null,
" " "name": "|--Téléphone mobile Huawei",
"pid": 1,
"static": 1,
"time ": 1588776159,
"last_time": null,
"delete_time": null
" },
" " {
" "id": 6,
"name": "|--iPhone" ,
"pid": 1,
"static": 1,
"time": 1588776200,
"last_time": null,
"delete _time": null
},
"id": 2,
"name ": "ordinateur",
"pid": 0,
"static": 0,
"time": 1588775190,
"last_time": null,
"delete_time": null
" },
" "id": 5,
"name": "|--Huawei Computer",
"pid": 2,
"static": 0,
"time": 1588776185,
"last_time": 1588816674,
"delete_time": null
},
"id": 7,
"name": "|--Apple Computer",
"pid": 2,
"static": 1,
"time": 1588776215,
"last_time": 1588816980,
à à
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!