递归HTML ACL保护菜单?

时间:2012-07-03 09:27:33

标签: php html acl

是否有任何关于如何创建受ACL保护的递归菜单的示例?

想法是即使用户没有父节点的读取权限,也可以打印具有读取访问权限的结束文档的遍历路径。

以下是它应该如何显示的HTML代码示例:

<ul>
    <li><a href="some_url">I have read access here</a>
        <ul>
            <li>I don't have read access here - only print node name (traversal)
                <ul>
                    <li><a href="some_url">I have read access here</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Acl有方法has_read_permission($ node_id) - 返回true / false

我设法生成完整的递归菜单但非acl受保护。

PHP是服务器后端。

数据库表结构:

node_id | parent id | node_content

THX

P.S。

PHP代码我用来生成非acl保护的递归菜单(它被采用到codeigniter框架):

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Menu extends MY_Controller {

    public static $menu = array();

    function index(){

        $permited_objects=$this->session->userdata('permited_objects');
        $session_email=$this->session->userdata('email');

        self::$menu[] = "<ul id=\"treemenu2\" class=\"treeview\">";

        $this -> _display_children(0, 0, $permited_objects);

        self::$menu[] = "</ul>";
        $menu_imploded = implode("", self::$menu);

        $menu_db = str_replace("<ul></ul>", " ", $menu_imploded);

        //write in db or return

        return $menu_db;

    }


    function _display_children($parent, $level) {

        $sql = "SELECT `title`, `doc_uid` 
                FROM `documents` 
                WHERE `parent_uid` = '" . $parent . "' 
                order by `title` 
                ASC";

        try {
            $this -> db -> trans_start();
            $query = $this -> db -> query($sql);
            $this -> db -> trans_complete();
        } catch (Exception $e) {
            $this -> _log_message('error', 'Model global\Generate_main_menu->execute() => ERROR=' . $e);
        }

        if ($level > 0)
            self::$menu[] = "<ul>";


        foreach ($query->result() as $row) {
                    self::$menu[] = '<li>';
                    self::$menu[] = '<a onclick="javascript: dms_display_document(\'' . $this->ec_crypt-> encode($row -> doc_uid) . '\');" href="#" >';
                    self::$menu[] = $row -> title;
                    self::$menu[] = '</a>';

                $this -> _display_children($row -> doc_uid, $level + 1);
            }

            if ($level > 0) {
                self::$menu[]='</ul>';
            }

            self::$menu[]='</li>';
        }
}

1 个答案:

答案 0 :(得分:0)

您可以通过在m-to-n表和users表之间创建nodes关系并在数据透视表中保留权限来自行完成:

<强> users_nodes

  • USER_ID
  • NODE_ID
  • can_read