public function getAll() { $data = $this->get(); // p($data);exit; $data = Data::tree($data, 'catname', 'id'); return $data; }
public function update_cache() { //获得表中的所有栏目数据 $category = Data::tree($this->all(), 'cname'); return F("category", $category); //file_put_contents()储存文件缓存 }
public function edit() { $menu = new \system\model\Menu(); if (IS_POST) { $data = json_decode(Request::post('menu')); foreach ($data as $m) { $d = []; if (!empty($m->id)) { $d['id'] = $m->id; } $d['pid'] = intval($m->pid); $d['title'] = $m->title; $d['permission'] = $m->permission; $d['url'] = $m->url; $d['append_url'] = $m->append_url; $d['icon'] = $m->icon; $d['orderby'] = intval($m->orderby); $d['is_display'] = $m->is_display; $d['mark'] = $m->mark; $d['is_system'] = $m->is_system; if ($d['mark'] && $d['title']) { $menu->replace($d); } } message('菜单更改成功'); } $data = $menu->get()->toArray(); $menus = Data::tree($data, 'title', 'id', 'pid'); return view()->with('menus', json_encode($menus, JSON_UNESCAPED_UNICODE)); }
public function addForum() { $db = M('forum'); if (IS_POST) { //处理表单提交 $data = $_POST; $data['create_time'] = time(); if ($dbid = $db->add($data)) { $path = MYPHP_TEMP_PATH . '/Dbid/Forum'; is_dir($path) || mkdir($path, 0777, true); chmod($path, 0777); if (file_put_contents($path . '/forumId.txt', $dbid)) { $this->success('保存版块成功', __APP__ . "?c=Forum&a=forum"); } } else { $this->error('添加失败,请重新添加'); } } $forum = $db->where('is_delete=0')->all(); $count = count($forum); $forum = alread_column(Data::tree($forum, 'fname', 'fid', 'father_fid')); // p($forum);die; $this->assign('count', $count); $this->assign('forum', $forum); $this->display(); }
public function edit() { //修改分类 if (IS_POST) { if (!$this->model->editCate()) { $this->error($this->model->error); } $this->success('修改成功', U('Category/index')); } $cid = Q('get.cid', 0, 'intval'); //类型循环分配 $type = M('type')->all(); $this->assign('typeData', $type); //旧数据 $oldCate = $this->model->where("cid={$cid}")->find(); $this->assign('oldCate', $oldCate); //处理分类 $allData = $this->model->all(); $cid = Q('cid', 0, 'intval'); $cids = $this->getSon($cid, $allData); $cids[] = $cid; $data = $this->model->where("cid NOT IN(" . implode(',', $cids) . ")")->all(); $data = Data::tree($data, 'cname'); $this->assign('data', $data); $this->display(); }
public function __init() { //获得模型实例 $this->db = K("Node"); $data = $this->db->order('list_order ASC, nid ASC')->all(); $node = Data::tree($data, "title", "nid", "pid"); $this->node = $node; }
public function getNode() { $res = $this->where("status='1'")->all(); if ($res) { $res = Data::tree($res, 'name', 'id', 'pid'); } return $res; }
public function columnList() { $column = K('Column')->getColumnType(); // $column = M('column')->where('display=1 AND is_delete=1')->all(); // p(Data::tree($column,'name','id','parent_id')); $this->assign('column', Data::tree($column, 'name', 'id', 'parent_id')); $this->display(); }
public function getAll($id = '') { if (empty($id)) { $data = $this->get(); return Data::tree($data, 'title', 'id'); } else { return $this->where('id', $id)->first(); } }
public function doSiteCategory() { $data = Db::table('web_category')->where('siteid', SITEID)->orderBy('cid', 'ASC')->get() ?: []; foreach ($data as $k => $v) { $data[$k]['url'] = __ROOT__ . '/index.php?s=content/home/category&siteid=' . v('site.siteid') . '&cid=' . $v['cid']; } $data = Data::tree($data, 'title', 'cid', 'pid'); View::with('data', $data); return View::make($this->template . '/content/category.php'); }
/** * 获取树状栏目 * 指定cid时过滤掉cid及其子栏目 * * @param int $cid * * @return mixed */ public function getLevelCategory($cid = 0) { $category = Db::table('web_category')->where('siteid', SITEID)->get(); if ($category) { $category = Data::tree($category, 'title', 'cid', 'pid'); if ($cid) { //编辑时在栏目选择中不显示自身与子级栏目 foreach ($category as $k => $v) { if ($v['cid'] == $cid || Data::isChild($category, $v['cid'], $cid)) { unset($category[$k]); } } } return $category; } }
public function edit() { //打印用户自定义常量 //print_const(); if (IS_POST) { if ($this->_db->edit_category()) { $this->ajax(array('state' => 1, 'message' => '栏目修改成功')); } else { $this->ajax(array('state' => 0, 'message' => $this->_db->error)); } } else { //分配编辑栏目旧的数据 $field = $this->_db->find(Q("cid")); //分配所有栏目 $category = $this->_db->all(); $category = Data::tree($category, 'cname'); foreach ($category as $n => $v) { //将父级栏目添加selected(选中状态) $v['selected'] = ''; if ($field['pid'] == $v['cid']) { $v['selected'] = ' selected="selected" '; } //将子栏目与自身添加disabled(禁止选择) $v['disabled'] = ''; if ($field['cid'] == $v['cid'] || Data::isChild($category, $v['cid'], $field['cid'])) { $v['disabled'] = ' disabled="disabled" class="disabled" '; } $category[$n] = $v; } //分配当前栏目数据 $this->field = $field; //分配栏目数据 $this->category = $category; $this->display(); } }
/** * 更新缓存 */ public function update_cache() { $nav = $this->order('list_order ASC,nid ASC')->all(); $data = Data::tree($nav, 'title', 'nid', 'pid'); return cache('navigation', $data); }
public function updateCache() { $data = $this->order("catorder ASC,cid ASC")->all(); //缓存数据 $cache = array(); if ($data) { $data = Data::tree($data, "catname", "cid", "pid"); foreach ($data as $cat) { //封面与链接栏目添加disabled属性 $cat["disabled"] = $cat["cattype"] != 1 ? 'disabled=""' : ''; $cat['cat_type_name'] = $this->categoryType[$cat['cattype']]; $cache[$cat['cid']] = $cat; } } if (S("category", $cache, 0)) { return true; } else { $this->error = '栏目缓存更新失败'; return false; } }
function updateCache() { $data = $this->join(NULL)->order(array("list_order" => "ASC", 'nid' => 'ASC'))->all(); $node = Data::tree($data, "title", "nid", "pid"); return cache("node", $node); }
public function updateCache() { $data = $this->order('list_order ASC, nid ASC')->all(); $node = Data::tree($data, "title", "nid", "pid"); return S("node", $node, 0); }
public function getAll() { $data = $this->get(); return Data::tree($data, 'cate_name', 'cate_id'); }
public function updateCache() { $db = V('category'); $db->view = array('model' => array('type' => INNER_JOIN, 'on' => 'category.mid=model.mid')); $categoryData = $db->order("catorder ASC,cid ASC")->all(); if (empty($categoryData)) { cache('category', null); return true; } $categoryData = Data::tree($categoryData, "catname", "cid", "pid"); $cacheData = array(); foreach ($categoryData as $n => $cat) { //封面与链接栏目添加disabled属性 $cat["disabled"] = $cat["cattype"] != 1 ? 'disabled=""' : ''; $cat['cat_type_name'] = $this->allowCategoryType[$cat['cattype']]; //栏目模板 switch ($cat['cattype']) { case 1: //普通栏目 $cat['template'] = 'template/' . C("WEB_STYLE") . '/' . $cat['list_tpl']; break; case 2: //封面栏目 $cat['template'] = 'template/' . C("WEB_STYLE") . '/' . $cat['index_tpl']; break; } $cacheData[$cat['cid']] = $cat; } if (cache("category", $cacheData)) { return true; } else { $this->error = '栏目缓存更新失败'; return false; } }
private function cid($field, $value) { //栏目权限模型 $categoryData = M('category')->all(); $category = Data::tree($categoryData, 'catname'); $html = "<select name='cid'>"; $html .= "<option value='0'>==选择栏目==</option>"; foreach ($category as $cat) { //外部链接关闭投稿 if (in_array($cat['cattype'], array(3))) { continue; } //非本模型栏目不显示 if ($this->mid != $cat['mid']) { continue; } //执行动作 if (isset($_GET['aid'])) { $action = 'edit'; } else { $action = 'add'; } //超级管理员不限或没有权限信息时允许操作 if (IS_SUPER_ADMIN || IS_WEBMASTER || empty($access)) { } else { $map['rid'] = $_SESSION['user']['rid']; $map['cid'] = $cat['cid']; $access = M('category_access')->where($map)->find(); if (!empty($access) && !$access[$access]) { continue; } } //除单文章与普通栏目外不可以发表 if (in_array($cat['cattype'], array(1, 4))) { $disabled = ''; } else { $disabled = ' disabled="" '; } //当前栏目默认选中 if ($this->cid == $cat['cid']) { $selected = ' selected="" '; } else { $selected = ''; } $html .= "<option value='{$cat['cid']}' {$disabled} {$selected}>{$cat['_name']}</option>"; } $html .= "</select>"; return $html; }
public function treeData() { $data = $this->where('is_delete=0')->all(); $d = Data::tree($data, 'cname', 'cid', 'pid'); return $d; }
/** * 修改商品 */ public function edit() { if (IS_POST) { if (!$this->model->editGoods()) { $this->error($this->model->error); } $this->success('修改成功', U('index')); } //所属分类 $typeData = M('category')->all(); $typeData = Data::tree($typeData, 'cname'); $this->assign('typeData', $typeData); //所属品牌 $brandData = M('brand')->all(); $this->assign('brandData', $brandData); //商品和商品详细表关联查询旧数据 $gid = Q('get.gid', 0, 'intval'); $oldData = M()->join("__goods__ g JOIN __goods_detail__ gd ON g.gid=gd.goods_gid")->where("gid={$gid}")->find(); $this->assign('oldData', $oldData); //关联商品属性和类型属性表获得旧规格和属性 $goodsArr = M()->join('__goods_attr__ ga JOIN __type_attr__ ta on ga.type_attr_taid=ta.taid')->where("ga.goods_gid={$gid}")->all(); foreach ($goodsArr as $k => $v) { if (!$v['tavalue'] == '') { $goodsArr[$k]['tavalue'] = explode(',', $v['tavalue']); } } $this->assign('goodsArr', $goodsArr); //旧列表和商品图册 $img = explode(',', $oldData['l_img']); $this->assign('img', $img); $this->display(); }
public function addCategory() { $field = array('id', 'name', 'parent_id'); $column = M('column')->field($field)->all(); // p($column);die; if (empty($column)) { $column = 0; } $column = Data::tree($column, 'name', 'id', 'parent_id'); $this->assign('column', $column); $this->display(); }
/** * 更新栏目缓存 */ public function updateCache() { $data = M('category')->all(); $data = Data::tree($data, 'cat_name', 'cid', 'pid'); return S('category', $data); }