public function edit()
 {
     $Group = D("Group");
     if (I("flag")) {
         if ($Group->create()) {
             $_POST['rules'] = implode(',', I('rules'));
             if ($Group->save($_POST)) {
                 $this->ajaxReturn(1);
                 //成功
             } else {
                 $this->ajaxReturn(0);
                 //失败
             }
         } else {
             $this->ajaxReturn($Group->getError());
         }
     } else {
         $menu = D('menu');
         $id = I('id');
         $map['id'] = array('eq', $id);
         $groupNews = $Group->where($map)->field("id,title,rules,status")->find();
         $groupNews['rules'] = explode(',', $groupNews['rules']);
         $data = $menu->field("id,pid,name")->select();
         $pid = 0;
         $treeList = makeTree($pid, $data);
         $tree = treeOutput($treeList, $groupNews['rules']);
         $this->assign("tree", $tree);
         $this->assign("groupNews", $groupNews);
         $this->display();
     }
 }
Exemplo n.º 2
0
function treeOutput($data, $groupRules = null)
{
    $str = '<ul>';
    foreach ($data as $k => $v) {
        if (!empty($v['child'])) {
            $p = "class='glyphicon glyphicon-plus'";
        } else {
            $p = '';
        }
        if ($v['pid']) {
            $d = "style='display:none'";
        }
        $str .= '<li ' . $d . '><input type="checkbox" name="rules[]"  value="' . $v['id'] . '"';
        if ($groupRules) {
            if (in_array($v['id'], $groupRules)) {
                $str .= 'checked';
            }
        }
        $str .= ' /><span>' . $v['name'] . '&nbsp;&nbsp;<i ' . $p . '></i></span>';
        if ($v['child']) {
            $str .= treeOutput($v['child'], $groupRules);
        }
    }
    $str .= "</ul>";
    return $str;
}