是否有任何如何創建ACL保護的遞歸菜單的例子?遞歸HTML 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) - 返回真/假
我已經成功地生成完整的遞歸菜單,但不acl保護。
PHP是服務器後端。
DB表結構:
node_id | parent id | node_content
THX
P.S.通過創建users
表和nodes
表並按住之間的m-to-n
關係
<?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>';
}
}
向我們展示您的代碼來創建遞歸菜單 –