1. 方式一
namespace appindexmodel;
use thinkModel;
class Classfiy extends Model{
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,
「静的」: 1,
「時間」 ": 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,
「静的」: 0,
「時間」: 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 ,
"名前": "苹果電脑",
"pid": 2,
"静的": 1,
"時間": 1588776215,
"last_time": 1588816980,
"delete_time": null,
"lev" : "!--"
}
],
"msg": ""}
方式二返還的データ格式是
{
"ret": 200,
"data": [
" " {
" "id": 1,
"name": "携帯電話",
"pid": 0,
"static": 1 ,
"time" ": 1588775166,
" last_time": null,
" " "name": "|--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 ": "computer",
"pid": 0,
"static": 0,
"time": 1588775190,
"last_time": null,
"delete_time": null
" },
" "id": 5,
"name": "|--Huawei コンピューター",
"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、
以上がthinkphp5 データの無制限の分類の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。