Function output problem, output is uncontrolled.
P粉318199689
P粉318199689 2022-07-25 18:08:47
0
4
781
function generateTree($items)
 {       
 $items = Db::name('tree')->column('id,pid,name');        
$tree = array();        
foreach ($items as $item) {
    if (isset($items[$item['pid']])) { 
       $items[$item['pid']]['son'][] = &$items[$item['id']];
        } else { 
        $tree[] = &$items[$item['id']]; 
       } 
       } 
       return $tree; 
       }
       $tree = generateTree(0); 
  function getTreeData($tree)
      { 
       foreach ($tree as $t) {
        echo "<li><span><i " . "class=\"icon-minus-sign\"></i>" .$t["name"]. "</span>\n<a href=\"info.php?id=".$t["id"]."\" target=\"_blank\">详细</a><ul>\n"; 
      if (isset($t['son'])) {
                getTreeData($t['son']);
             } 
             echo "</ul>\n</li>\n"; 
            } 
        } 
        $list = getTreeData($tree);
        $this->assign('list',$list);    
    return $this->view->fetch();
 }

1.jpg

The static file is like this1-3.jpg

is directly output to 1-1.jpg

and is out of control. If you use variables2.jpg

Only output one level, and there will be no more after that.2-2.jpg

Masters, please teach me how to write, thank you.

P粉318199689
P粉318199689

reply all(2)
autoload

You are not out of control, this function echoes, just delete the echo, and the array is returned directly with variables

image.png

Splice directly in the view

autoload

Don’t write anything on the page, just print the variables transferred from the controller to see what they are

  • reply is an array Array ( [0] => Array ( [id] => 1 [pid] => 0 [name] => Youlou [son] => Array ( [0] => Array ( [id] => 2 [pid ] => 1 [name] => 火[son]
    P粉318199689 author 2022-07-25 21:30:55
  • reply array(14) { [1] => array(3) { ["id"] => int(1) ["pid"] => int(0) ["name"] => string(6) "There is a building" } [2] => array(3) { ["id"] => int(2) ["pid"] => int(1) ["name"] => string(3) "burn" } [3] => array(3) { ["id"] => int(3) ["pid"] => int(2) ["name"] => string(6) "Jingbao" This is the array read from the database
    P粉318199689 author 2022-07-25 21:33:03
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template