PHP / Codeigniter Nestable List

时间:2014-11-11 00:54:43

标签: php jquery codeigniter

有人要解决的简单问题我希望,(我已经写过这个),我有一个页面,每个页面的页面记录有一个parent_id我需要输出所有在其父页面下正确嵌套的页面。我设法让输出显示两个级别,但我现在陷入困境。

最终目标是使用JQuery Nestable允许我的用户重新排序页面并设置新的父母。

修改

控制器:

public function navigation() {
    if($this->session->userdata('logged_in')) {

        $session_data = $this->session->userdata('logged_in');
        $data['auid'] = $session_data['user_user_id'];
        $data['userName'] = $session_data['user_fullname'];
        $data['gravatar'] = gravatar($session_data['user_email'], 30, FALSE);

        $pages = $this->admin_m->getAllTopPages();
        foreach ($pages as $p) {
            $pid = $p->page_id;
            $children = $this->admin_m->getAllChildPages($pid);
            if($children) {
                $p->children = $children;
            }
        }


        $data['pages'] = $pages;
        $data['current'] = 'navigation';
        $this->load->view('admin/partials/header_v', $data);
        $this->load->view('admin/partials/top-bar_v');
        $this->load->view('admin/partials/side-bar_v');
        $this->load->view('admin/navigation_v');
        $this->load->view('admin/partials/footer_v');
    } else {
        redirect('admin/login', 'refresh');
    }
}

型号:

public function getAllTopPages() {
    $query = $this->db->get_where('yell_page', array('page_parent_id'=>'-1'));
    return $query->result();
}

public function getAllChildPages($pid) {
    $this->db->select('page_id, page_name, page_parent_id');
    $this->db->from('yell_page');
    $this->db->where('page_parent_id =', $pid);
    $this->db->where('page_parent_id !=', '-1');
    $query = $this->db->get();
    return $query->result();
}

查看:

<div class="panel-body">
    <div class="dd" id="nestable_list_2">
        <ol class="dd-list">
        <?php
        foreach($pages as $p) {
           echo '<li class="dd-item" data-id="'.$p->page_id.'">';
              echo '<div class="dd-handle">'.$p->page_name.'</div>';
              echo '<ol class="dd-list">';
              if(isset($p->children)) {
                 foreach($p->children as $obj) {
                   echo '<li class="dd-item" data-id="'.$obj->page_id.'"><div class="dd-handle">'.$obj->page_name.'</div></li>';
                 }
              }
              echo '</ol>';
           echo '</li>';
        }
        ?>
        </ol>
    </div>
</div>

我越来越接近但现在的问题是我只能获得两个级别的数据,这可能会更多。

0 个答案:

没有答案