function getTypeTr($fid = 0, $num = 0) { $mOb = M("Type"); $arr = $mOb->where("fid={$fid} and state=0")->select(); $trStr = ""; //产生缩进字符串 $indentStr = str_repeat("--", $num); $num++; foreach ($arr as $v) { $trStr .= "<tr><td>{$v['id']}</td><td>{$indentStr}{$v['tname']}</td><td><a href='" . U("Type/update", array('id' => $v['id'])) . "'>修改</a> | <a href='" . U('Type/delete', array('id' => $v['id'])) . "'>删除</a></td></tr>"; //看一看,有没有子类,自己调用自己 $trStrSon = getTypeTr($v['id'], $num); $trStr .= $trStrSon; } return $trStr; }
public function oper() { $str = getTypeTr(0); $this->assign('str', $str); $this->display(); }