Пример #1
0
function node_son_id($node, $pid = 0)
{
    $arr = array();
    foreach ($node as $k => $v) {
        if ($v['pid'] == $pid) {
            $arr[] = $v['id'];
            $arr = array_merge(node_son_id($node, $v['id']), $arr);
        }
    }
    return $arr;
}
Пример #2
0
 /**
  * 删除节点
  */
 public function delNode()
 {
     $db = M('node');
     if ($db->in(node_son_id($_POST['id']))->del()) {
         echo 1;
         exit;
     }
 }
Пример #3
0
/**
 * 获取节点的所有子节点ID
 * @param int $nid 节点ID
 * @param array $field 主键字段名(如:nid、id)、父字段名(如:pid)。默认:array('nid','pid');
 * @param $data 默认的数据,一般不传
 * @return 子节点数组
 */
function node_son_id($nid, $field = array('nid', 'pid'), $data = NULL)
{
    $db = M('node');
    if ($nid !== FALSE) {
        $n = $db->field($field[0])->where($field[0] . '=' . $nid)->findall();
    } else {
        $n = $data;
    }
    $nodes = array($field[0] => array());
    foreach ($n as $value) {
        $v = $db->field($field[0])->where($field[1] . '=' . $value[$field[0]])->findall();
        if ($v) {
            $a = node_son_id(FALSE, $field, $v);
            foreach ($a[$field[0]] as $v_a) {
                $nodes[$field[0]][] = $v_a;
            }
        }
        $nodes[$field[0]][] = $value[$field[0]];
    }
    return $nodes;
}