/** * 编辑分类 * @author jry <*****@*****.**> */ public function edit_with_tree($id, $group = 1) { if (IS_POST) { $category_object = D('Category'); $data = $category_object->create(); if ($data) { if ($category_object->save() !== false) { $this->success('更新成功', U('index', array('group' => I('post.group')))); } else { $this->error('更新失败'); } } else { $this->error($category_object->getError()); } } else { // 获取分类信息 $category_object = D('Category'); $info = $category_object->find($id); // 获取前台模版供选择 if (C('CURRENT_THEME')) { $template_list = \Common\Util\File::get_dirs(getcwd() . '/Theme/' . C('CURRENT_THEME') . '/Article/article'); } else { $template_list = \Common\Util\File::get_dirs(getcwd() . '/Application/Article/View/Home/article'); } foreach ($template_list['file'] as $val) { $val = substr($val, 0, -5); if (strstr($val, 'index')) { $template_list_index[$val] = $val; } elseif (strstr($val, 'detail')) { $template_list_detail[$val] = $val; } } // 使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('编辑分类')->setPostUrl(U('edit', array('id' => $id, 'group' => $group)))->addFormItem('id', 'hidden', 'ID', 'ID')->addFormItem('group', 'radio', '分组', '分组', D('Category')->group_list())->addFormItem('pid', 'select', '上级分类', '所属的上级分类', select_list_as_tree('Category', array('group' => $group), '顶级分类'))->addFormItem('title', 'text', '分类标题', '分类标题')->addFormItem('doc_type', 'radio', '分类内容模型', '分类内容模型', select_list_as_tree('Type'))->addFormItem('url', 'text', '链接', 'U函数解析的URL或者外链', null, $info['doc_type'] == 1 ?: 'hidden')->addFormItem('content', 'kindeditor', '内容', '单页模型填写内容', null, $info['doc_type'] == 2 ?: 'hidden')->addFormItem('index_template', 'select', '模版', '文档列表或封面模版', $template_list_index, $info['doc_type'] > 2 ?: 'hidden')->addFormItem('detail_template', 'select', '详情页模版', '单页使用的模版或其他模型文档详情页模版', $template_list_detail, $info['doc_type'] > 1 ?: 'hidden')->addFormItem('icon', 'icon', '图标', '菜单图标')->addFormItem('sort', 'num', '排序', '用于显示的顺序')->addFormItem('post_auth', 'radio', '投稿权限', '前台用户投稿权限', $category_object->post_auth())->setFormData($info)->setExtraHtml($this->extra_html)->setTemplate('Admin/builder/form')->display(); } }
/** * 编辑分类 * @author jry <*****@*****.**> */ public function edit($id, $group) { if (IS_POST) { $category_object = D('Category'); $data = $category_object->create(); if ($data) { if ($category_object->save() !== false) { $this->success('更新成功', U('Category/index', array('group' => I('post.group')))); } else { $this->error('更新失败'); } } else { $this->error($category_object->getError()); } } else { //获取分类信息 $category_object = D('Category'); $info = $category_object->find($id); //获取前台模版供选择 $current_theme = D('SystemTheme')->where(array('current' => 1))->order('id asc')->getField('name'); //从系统主题数据表获取当前主题的名称 $template_list = \Common\Util\File::get_dirs(getcwd() . '/Application/Home/View/' . $current_theme . '/Document'); foreach ($template_list['file'] as $val) { $val = substr($val, 0, -5); if (strstr($val, 'index')) { $template_list_index[$val] = $val; } elseif (strstr($val, 'detail')) { $template_list_detail[$val] = $val; } } //使用FormBuilder快速建立表单页面。 $builder = new \Common\Builder\FormBuilder(); $builder->setMetaTitle('编辑分类')->setPostUrl(U('Admin/Category/edit/id/' . $id . '/group/' . $group))->addFormItem('id', 'hidden', 'ID', 'ID')->addFormItem('group', 'radio', '分组', '分组', C('CATEGORY_GROUP_LIST'))->addFormItem('pid', 'select', '上级分类', '所属的上级分类', select_list_as_tree('Category', array('group' => $group), '顶级分类'))->addFormItem('title', 'text', '分类标题', '分类标题')->addFormItem('doc_type', 'radio', '分类内容模型', '分类内容模型', select_list_as_tree('DocumentType'))->addFormItem('url', 'text', '链接', 'U函数解析的URL或者外链', null, $info['doc_type'] == 1 ?: 'hidden')->addFormItem('content', 'kindeditor', '内容', '单页模型填写内容', null, $info['doc_type'] == 2 ?: 'hidden')->addFormItem('index_template', 'select', '模版', '文档列表或封面模版', $template_list_index, $info['doc_type'] > 2 ?: 'hidden')->addFormItem('detail_template', 'select', '详情页模版', '单页使用的模版或其他模型文档详情页模版', $template_list_detail, $info['doc_type'] > 1 ?: 'hidden')->addFormItem('icon', 'icon', '图标', '菜单图标')->addFormItem('sort', 'num', '排序', '用于显示的顺序')->addFormItem('post_auth', 'radio', '投稿权限', '前台用户投稿权限', $category_object->post_auth())->setFormData($info)->setExtraHtml($this->extra_html)->display(); } }