本文整理汇总了PHP中tree::get_tree_category方法的典型用法代码示例。如果您正苦于以下问题:PHP tree::get_tree_category方法的具体用法?PHP tree::get_tree_category怎么用?PHP tree::get_tree_category使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::get_tree_category方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
public function add($id = '')
{
require APPPATH . 'libraries/tree.class.php';
if ($id) {
$query = $this->db->where(array('catid' => $id))->get('category')->row_array();
}
$this->data['item'] = $query;
$categorys = $this->categorys;
$tree = new tree();
$tree->icon = array(' │ ', ' ├─ ', ' └─ ');
$tree->nbsp = ' ';
$string = '<select name="parentid">';
$string .= "<option value='0'>≡ 作为一级栏目 ≡</option>";
$str = "<option value='\$catid' \$selected>\$spacer \$catname</option>;";
$str2 = "<optgroup label='\$spacer \$catname'></optgroup>";
$tree->init($categorys);
$string .= $tree->get_tree_category(0, $str, $str2, $query['parentid']);
$string .= '</select>';
$this->data['categorys'] = $string;
$this->repair(false);
$this->load->view('category/add', $this->data);
}
示例2: select_category
/**
* 栏目选择
* @param string $file 栏目缓存文件名
* @param intval/array $catid 别选中的ID,多选是可以是数组
* @param string $str 属性
* @param string $default_option 默认选项
* @param intval $modelid 按所属模型筛选
* @param intval $type 栏目类型
* @param intval $onlysub 只可选择子栏目
* @param intval $siteid 如果设置了siteid 那么则按照siteid取
*/
public static function select_category($file = '', $catid = 0, $str = '', $default_option = '', $modelid = 0, $type = -1, $onlysub = 0, $siteid = 0, $is_push = 0)
{
require_once "Tree.class.php";
$tree = new tree();
if (!$siteid) {
$siteid = get_siteid();
}
if ($modelid) {
$result = D('Category')->where('siteid = %d and modelid = %d', $siteid, $modelid)->select();
} else {
$result = D('Category')->where('siteid = %d', $siteid)->select();
}
$string = '<select ' . $str . '>';
if ($default_option) {
$string .= "<option value='0'>{$default_option}</option>";
}
if (is_array($result)) {
foreach ($result as $r) {
if ($siteid != $r['siteid'] || $type >= 0 && $r['type'] != $type) {
continue;
}
$r['selected'] = '';
if (is_array($catid)) {
$r['selected'] = in_array($r['id'], $catid) ? 'selected' : '';
} elseif (is_numeric($catid)) {
$r['selected'] = $catid == $r['id'] ? 'selected' : '';
}
$r['html_disabled'] = "0";
if (!empty($onlysub) && $r['child'] != 0) {
$r['html_disabled'] = "1";
}
$categorys[$r['id']] = $r;
if ($modelid && $r['modelid'] != $modelid) {
unset($categorys[$r['catid']]);
}
}
}
$str = "<option value='\$id' \$selected>\$spacer \$catname</option>;";
$str2 = "<optgroup label='\$spacer \$catname'></optgroup>";
$tree->init($categorys);
$string .= $tree->get_tree_category(0, $str, $str2);
$string .= '</select>';
return $string;
}