- 1、控制器
- public function edit() {
- $id=(int)$_GET['id'];
- $model=M('category');
- $result=$model->where("status=1 and id=$id")->find();
- $this->assign('cate',$result);
- import('@.ORG.Tree');
- $tree=new Tree('Category',array('id','pid','name','fullname'));
- $CateList=$tree->getlist();
- $this->assign('list',$CateList);
- $this->display();
- }
- 2、模版显示
- <div class="unit">
- <label>分 类:</label>
- <select name="pid">
- <option value="0">顶级分类</option>
- <volist name="list" id="vo">
- <eq name="cate.pid" value="$vo.id"> //如果当前的PID和循环的ID相同,选中它
- <option value="{$vo.pid}" selected>{$vo.fullname}</option>
- <else /> //如果不相同,循环其它分类
- <option value="{$vo.pid}" >{$vo.fullname}</option>
- </eq>
- </volist>
- </select>
- </div>
转载于:https://blog.51cto.com/rc699/1125430