Home > php教程 > php手册 > ThinkPHP 无限分类输出一维数组model

ThinkPHP 无限分类输出一维数组model

WBOY
Release: 2016-06-07 11:41:51
Original
1124 people have browsed it

ThinkPHP 无限分类输出一维数组model
<?php <br /> /*<br>  * $tableName 表名<br>  * $prent_me_str 父ID字段<br>  * $order 排序字段<br>  * Yi210.com<br>  */<br> namespace Admin\Model;<br> use Think\Model;<br> class TreeModel<br> {<br>     private $Model;<br>     private $prent_me_str = 'pid';<br>     private $order = 'sort';<br> <br>     public function __construct($tableName)<br>     {<br>         $this->Model = M( $tableName );<br>     }<br> <br>     public function getTree( $parent_id = 0, $level = 0 )<br>     {<br>         global $temp;<br>         $order = $this->order;<br>         if ( $order ) {<br>             $data = $this->Model->where("$this->prent_me_str = '" . $parent_id . "'")->order("$order asc")->select();<br>         } else {<br>             $data = $this->Model->where("$this->prent_me_str = '" . $parent_id . "'")->select();<br>         }<br>         $str = $level ? '|--' : '';<br>         $level++;<br>         if ( !empty($data) ) {<br>             foreach ($data as $key => $value) {<br>                 $l = $level - 1;<br>                 $value['str'] = str_repeat(' ', $l * 4) . $str;<br>                 $value['isprent'] = $this->isPrent( $value['id'] );<br>                 $temp[] = $value;<br>                 $this->getTree($value['id'], $level);<br>             }<br>         }<br>         return $temp;<br>     }<br> <br> }<br> <br> 输出格式:<br> 水果<br>    |-- 苹果<br>       |-- 青苹果<br>    |-- 梨个站:http://www.yi210.com/archives/948.html

QQ交流群:323540593

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template