/** * 类目选择 * @param string $file 栏目缓存文件名 * @param intval/array $catid 选中的ID,多选是可以是数组 * @param string $str 属性 * @param string $default_option 默认选项 */ public static function taxonomy($terms = '', $taxonomy = 'category', $catid = 0, $default_option = array()) { if (is_numeric($catid)) { $catid = array($catid); } $tree = new Tree(); $tree->init($terms); $string = '<ul id="' . $taxonomy . 'checklist" class="' . $taxonomy . 'checklist">'; $string .= $tree->get_taxonomy_tree(0, $catid); $string .= '</select>'; return $string; }
/** * 栏目选择 * @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) { $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; }