thinkphp5 データの無制限の分類

远方*
リリース: 2022-03-11 15:14:01
オリジナル
143 人が閲覧しました

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 サイトの他の関連記事を参照してください。

関連ラベル:
php
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!