有没有关于如何创建受 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是服务器后端。
数据库表结构:
node_id | parent id | node_content
谢谢
附言
我用来生成非 acl 保护的递归菜单的 PHP 代码(它被用于 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>';
}
}