/** * 添加漏洞报告 */ public function add() { //默认显示添加表单 if (!IS_POST) { $this->assign("category", getSortedCategory(M('category')->select())); $this->display(); } if (IS_POST) { //如果用户提交数据 $model = D("Post"); $model->time = time(); $model->user_id = 1; if (!$model->create()) { // 如果创建失败 表示验证没有通过 输出错误提示信息 $this->error($model->getError()); exit; } else { if ($model->add()) { $this->success("添加成功", U('post/index')); } else { $this->error("添加失败"); } } } }
/** * 获取排序后的分类 * @param [type] $data [description] * @param integer $pid [description] * @param string $html [description] * @param integer $level [description] * @return [type] [description] */ function getSortedCategory($data, $pid = 0, $html = "|---", $level = 0) { $temp = array(); foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $str = str_repeat($html, $level); $v['html'] = $str; $temp[] = $v; $temp = array_merge($temp, getSortedCategory($data, $v['id'], '|---', $level + 1)); } } return $temp; }
public function index() { $xuhao = 1; $model = M('member'); $tmodel = M('setting'); $title = $tmodel->where('id=1')->select(); $user = $model->order('jifen ASC')->where('type=1')->select(); // fix bug issued by phith0n 13:59 2016/1/25 $this->assign('title', $title); $this->assign('xuhao', $xuhao); $this->assign('user', getSortedCategory($user)); $this->display(); }
public function index($key = "") { if ($key == "") { $model = M('member'); } else { $where['title'] = array('like', "%{$key}%"); $where['name'] = array('like', "%{$key}%"); $where['_logic'] = 'or'; $model = M('member')->where($where); } $user = $model->limit($Page->firstRow . ',' . $Page->listRows)->where($where)->order('jifen ASC')->where('type=1')->select(); $this->assign('user', getSortedCategory($user)); $this->display(); }
/** * 更新文章信息 * @param [type] $id [文章ID] * @return [type] [description] */ public function update($id) { //默认显示添加表单 if (!IS_POST) { $model = M('post')->where('id=' . $id)->find(); $this->assign("category", getSortedCategory(M('category')->select())); $this->assign('post', $model); $this->display(); } if (IS_POST) { $model = D("Post"); if (!$model->create()) { $this->error($model->getError()); } else { if ($model->save()) { $this->success("更新成功", U('post/index')); } else { $this->error("更新失败"); } } } }
/** * 更新分类信息 * @param [type] $id [分类ID] * @return [type] [description] */ public function update() { //默认显示添加表单 if (!IS_POST) { $model = M('category')->find(I('id')); $this->assign('cate', getSortedCategory(M('category')->select())); $this->assign('model', $model); $this->display(); } if (IS_POST) { $model = D("Category"); if (!$model->create()) { $this->error($model->getError()); } else { // dd(I());die; if ($model->save()) { $this->success("分类更新成功", U('category/index')); } else { $this->error("分类更新失败"); } } } }