Ejemplo n.º 1
0
 public function displayChildren($category_id, $level)
 {
     //TODO;
     exit;
     $con = mysql_connect("localhost", "root", "123456");
     if (!$con) {
         die('数据库连接失败: ' . mysql_error());
     }
     mysql_select_db('test', $con);
     // 获得当前节点的所有孩子节点(直接孩子,没有孙子)
     $result = mysql_query("SELECT * FROM category WHERE parent_id='{$category_id}'");
     // 遍历孩子节点,打印节点
     while ($row = mysql_fetch_array($result)) {
         // 根据层级,按照缩进格式打印节点的名字
         // 这里只是打印,你可以将以下代码改成其他,比如把节点信息存储起来
         echo str_repeat('--', $level) . $row['category_name'] . "<br/>";
         // 递归的打印所有的孩子节点
         displayChildren($row['category_id'], $level + 1);
     }
 }
Ejemplo n.º 2
0
function displayChildren(Smarty $smarty, $tree)
{
    $templateVars = $smarty->get_template_vars();
    $currentController = strtolower($templateVars['__ZF__']['controller']);
    $currentAction = strtolower($templateVars['__ZF__']['action']);
    $string = "";
    $string .= '<ul>';
    foreach ($tree as $child) {
        // if it is a root
        if (null === $child->inherits) {
            $string .= '<li>';
            $string .= '<div>' . $child->name . '</div>';
            if (is_array($child->children)) {
                $string .= displayChildren($smarty, $child->children);
            }
            $string .= '</li>';
        } else {
            if (!is_array($child->children)) {
                $string .= '<li>';
                if ("category" === $currentController && $child->identifier === $currentAction) {
                    $string .= '<div class="on">' . $child->name . " (" . $child->howmany . ")" . '</div>';
                } else {
                    $string .= '<a href="/category/' . $child->identifier . '">' . $child->name . " (" . $child->howmany . ")" . '</a>';
                }
                $string .= '</li>';
            } else {
                $string .= '<li>';
                $string .= '<div>' . $child->name . '</div>';
                if (is_array($child->children)) {
                    $string .= displayChildren($smarty, $child->children);
                }
                $string .= '</li>';
            }
        }
    }
    $string .= '</ul>';
    return $string;
}
Ejemplo n.º 3
0
$pages = array("Clients" => array("link" => "clients", "children" => array("New Client" => "client", "View All" => "clients")), "Users" => array("link" => "users", "children" => array("New User" => "user")), "Settings" => "settings");
foreach ($pages as $display => $page) {
    if (!is_array($page)) {
        if (in_array($page, $u_permissions) || $u_all_access) {
            echo "<li><a href='{$page}'>{$display}</a></li>";
        }
    } else {
        $is_link = $page['link'] ? 1 : 0;
        if ($u_all_access) {
            $access_to_parent = 1;
        } else {
            $access_to_parent = $is_link ? in_array($page['link'], $u_permissions) : 0;
        }
        $access_to_children = accessToChildren($page['children'], $u_permissions, $u_all_access);
        if ($access_to_parent || $access_to_children) {
            if ($access_to_parent) {
                echo "<li><a href='{$page['link']}'>{$display}</a>";
            } elseif (!$access_to_parent && $access_to_children || !$is_link && $access_to_children) {
                // what
                echo "<li><span>{$display}</span>";
            }
            if ($access_to_children) {
                echo "<ul>";
                displayChildren($page['children'], $u_permissions, $u_all_access);
                echo "</ul>";
            }
            echo "</li>";
        }
    }
}
Ejemplo n.º 4
0
 function displayChildren(&$container)
 {
     echo '<br />' . $container->name . ' has children:<br />';
     foreach ($container->children as $child) {
         echo $child->name . ' whose parent is ' . $child->parent->name . '<br />';
     }
     foreach ($container->children as $child) {
         displayChildren($child);
     }
 }