Exemple #1
0
 public function detail()
 {
     $id = intval($_GET['lid']);
     $info = M('News')->where(array('id' => $id, 'uid' => 0, 'status' => 1))->find();
     if (empty($info)) {
         $this->error('抱歉,没有找到该文章哦!');
     } else {
         $menu = M('Menu')->where(array('status' => 1))->order('sort DESC')->select();
         $info['menu'] = Menu::getParents($menu, $info['menu_id']);
         $menus = menu::unlimitedForLayer($menu);
         $this->news = M('News')->where(array('status' => 1))->field(array('id', 'uid', 'title', 'addtime'))->order('asort DESC,addtime DESC')->limit(12)->select();
         $this->menu = $menus;
         $this->info = $info;
         $this->seo_set($info['title']);
         $this->display();
     }
 }
 public function news_edit()
 {
     if (IS_POST) {
         $id = intval($_POST['id']);
         $data = array('title' => str_rp(trim($_POST['title'])), 'menu_id' => intval($_POST['ac_id']), 'status' => intval($_POST['status']), 'asort' => intval($_POST['article_sort']), 'read_count' => intval($_POST['read_count']), 'des' => str_rp(trim($_POST['des'])), 'content' => str_rp(trim($_POST['content'])), 'tag' => intval($_POST['tag']));
         //图片上传
         if (!empty($_FILES['article_pic']['name'])) {
             $filename = 'newsImg_' . $id;
             $param = array('savePath' => 'artic/', 'subName' => '', 'files' => $_FILES['article_pic'], 'saveName' => $filename, 'saveExt' => '');
             $up_return = upload_one($param);
             if ($up_return == 'error') {
                 $this->error('图片上传失败');
                 exit;
             } else {
                 $data['img'] = $up_return;
             }
         }
         D('News')->where('id=' . $id)->save($data);
         $this->success('操作成功', U('news'));
         exit;
     } else {
         $id = intval($_GET['id']);
         if ($id) {
             $vo = D('News')->relation(true)->where('id=' . $id)->find();
             $ac_list = $this->art_class->order('sort asc')->select();
             $ac_list = Menu::unlimitedForLayer($ac_list);
             $this->assign('vo', $vo);
             $this->assign('ac_list', $ac_list);
             $this->display('news_edit');
         }
     }
 }