當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Tree::load方法代碼示例

本文整理匯總了PHP中Tree::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tree::load方法的具體用法?PHP Tree::load怎麽用?PHP Tree::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tree的用法示例。


在下文中一共展示了Tree::load方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildFromString

 /**
  * get html dom from string
  * @param $str
  * @param bool $lowercase
  * @param bool $forceTagsClosed
  * @param $target_charset
  * @param bool $stripRN
  * @param $defaultBRText
  * @param $defaultSpanText
  * @return bool|Tree
  */
 static function buildFromString($str, $lowercase = true, $forceTagsClosed = true, $target_charset = self::DEFAULT_TARGET_CHARSET, $stripRN = true, $defaultBRText = self::DEFAULT_BR_TEXT, $defaultSpanText = self::DEFAULT_SPAN_TEXT)
 {
     $dom = new Tree(null, $lowercase, $forceTagsClosed, $target_charset, $stripRN, $defaultBRText, $defaultSpanText);
     if (empty($str) or strlen($str) > self::MAX_FILE_SIZE) {
         $dom->clear();
         return false;
     }
     $dom->load($str, $lowercase, $stripRN);
     return $dom;
 }
開發者ID:jasonshaw,項目名稱:framework-1,代碼行數:21,代碼來源:Tree.php

示例2: foreach

            echo '<ul>';
            foreach ($tree as $node) {
                $selected = !empty($node['state']['selected']) ? 'checked' : '';
                echo "<li><input type=\"checkbox\" {$selected}>" . $node['name'];
                if (!empty($node['children'])) {
                    $this->printSelectTree($node['children']);
                }
                echo '</li>';
            }
            echo '</ul>';
        }
    }
}
//demo
//所有數據
$data = [['id' => 1, 'pid' => 0, 'name' => 'a'], ['id' => 2, 'pid' => 0, 'name' => 'b'], ['id' => 3, 'pid' => 0, 'name' => 'c'], ['id' => 4, 'pid' => 2, 'name' => 'd'], ['id' => 5, 'pid' => 1, 'name' => 'e'], ['id' => 6, 'pid' => 5, 'name' => 'f'], ['id' => 7, 'pid' => 5, 'name' => 'g'], ['id' => 8, 'pid' => 5, 'name' => 'h'], ['id' => 9, 'pid' => 4, 'name' => 'i'], ['id' => 10, 'pid' => 9, 'name' => 'j'], ['id' => 11, 'pid' => 0, 'name' => 'k']];
//有權限查看的數據
$allowed_data = [['id' => 1, 'pid' => 0, 'name' => 'a'], ['id' => 2, 'pid' => 0, 'name' => 'b'], ['id' => 10, 'pid' => 9, 'name' => 'j']];
//選中的數據
$selected_keys = [1, 2, 9];
$tree = new Tree();
$tree->load($data, $allowed_data, $selected_keys);
echo "<style>li{list-style-type:none;}</style>";
echo "完整樹:<br/>";
$tree->printTree($tree->buildTree());
echo "------------------------------------------------------<br/>";
echo "有權限的樹:<br/>";
$tree->printAllowedTree($tree->buildTree());
echo "------------------------------------------------------<br/>";
echo "有選擇功能的樹:<br/>";
$tree->printSelectTree($tree->buildTree());
開發者ID:Suninus,項目名稱:BeautifulPHP,代碼行數:31,代碼來源:Tree.php

示例3: loadChildren

 /**
  * Load node children
  *
  * @param   int  $recursionLevel
  * @return  Node
  */
 public function loadChildren($recursionLevel = 0)
 {
     $this->_tree->load($this, $recursionLevel);
     return $this;
 }
開發者ID:schpill,項目名稱:standalone,代碼行數:11,代碼來源:Node.php


注:本文中的Tree::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。