Пример #1
0
 public function del()
 {
     $id = I('id', NULL);
     if (!empty($id)) {
         if (is_array($id)) {
             $where = 'id  in (' . implode(',', $id) . ')';
         } else {
             $where = 'id = ' . $id;
         }
         $article = new ArticleModel();
         if (false !== $article->where($where)->delete()) {
             $this->message('删除成功', __URL__ . '/index');
         } else {
             $this->message('删除失败:' . $article->getError(), __URL__ . '/index');
         }
     } else {
         $this->message('请选择删除对象', __URL__ . '/index');
     }
 }
Пример #2
0
 /**
  * 编辑文章推荐
  */
 public function edit_tj()
 {
     $id = $_GET['id'];
     $is_tj = $_GET['is_tj'];
     if ($is_tj == 1) {
         $is_tj = 0;
     } else {
         $is_tj = 1;
     }
     $M = new ArticleModel();
     $data = array("is_tj" => $is_tj);
     $rs = $M->where("id=" . $id)->save($data);
     if ($rs) {
         $this->success("操作成功!");
     } else {
         $this->error("操作失败!");
     }
 }
Пример #3
0
 /**
  * 删除数据
  */
 function del()
 {
     //implode序列化主键Id为:1,2,3,...以便批量删除
     $del_id = $_POST['del_id'];
     $catid = implode($del_id, ',');
     //实例化模型
     $category = new CategoryModel();
     $article = new ArticleModel();
     $menu_items = new MenuItemModel();
     //删除分类
     if ($category->delete($catid)) {
         //删除文章的where语句
         $where = array('catid' => array('in', $catid));
         //删除文章
         $article->where($where)->delete();
         //删除类别后删除菜单项中的类别
         $menu_where = array('type_id' => array('in', $catid), 'type' => 'Category');
         $menu_items->where($menu_where)->delete();
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->success('分类,下属文章以及相应的菜单项删除成功~~~~');
     } else {
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->error('分类删除失败!' . $category->getError());
     }
 }
Пример #4
0
    /**
     * 生成RSS
     */
    function generate_rss()
    {
        //得到每一天所有的最新文章
        $article = new ArticleModel();
        $where = array('created' => array('gt', date("Y-m-d")));
        $list = $article->where($where)->select();
        //定义生成RSS的字符串
        $str = '';
        $str .= '<?xml version="1.0" encoding="utf-8"?>
					<rss version="2.0">
						<channel>
							<title>' . C('SITENAME') . '</title>
							<link>' . C('SITEURL') . '</link>
							<keywords>' . C('SITE_KEYWORDS') . '</keywords>
							<description>' . C('SITE_DESCRIPTION') . '</description>';
        foreach ($list as $art) {
            $str .= '
							<item>
								<title>' . $art['title'] . '</title>
								<link>' . C('SITEURL') . '/Article/view/id/' . $art['id'] . '</link>
								<description>' . $art['description'] . '</description>
								<pubDate>' . $art['created'] . '</pubDate>
							</item>';
        }
        $str .= '
							</channel>
						</rss>
						';
        //将数据写入文件
        $handle = fopen('rss.xml', 'w');
        if (fwrite($handle, $str) !== false) {
            $this->assign("jumpUrl", "__APP__/Manage/index");
            $this->success('RSS文件写入成功,文件路径为根目录');
        } else {
            $this->assign("jumpUrl", "__APP__/Manage/index");
            $this->error('RSS文件写入失败,请联系管理员');
        }
        fclose($handle);
    }
Пример #5
0
 public function articleList()
 {
     if (!empty($_GET['t'])) {
         $condition['article_type_id'] = $_GET['t'];
     }
     $article = new ArticleModel();
     $article_res = $article->where($condition)->relation(true)->findAll();
     $this->assign('article_res', $article_res);
     $this->display();
 }
Пример #6
0
 public function getModelFromSlug($slug)
 {
     $cache = new Cache();
     $cache->setLocalPath($slug . '_article');
     $cache->load();
     if ($cache->isValid()) {
         $model = new ModelWrapper($cache->getData());
     } else {
         $model = ArticleModel::where('slug', '=', $slug)->with('contents')->first();
         if (empty($model)) {
             throw new HttpException(404);
         }
         $cache->setData($model);
         $cache->save();
     }
     return $model;
 }
Пример #7
0
 /**
  * 单元删除页面
  */
 function del()
 {
     //因为删除一个单元,就要删除其手下的分类类别,而删除分类类别后就要删除该类别下面的文章
     //所有必须使用关联操作来执行
     //序列化主键Id为:1,2,3,...以便批量删除
     $del_id = $_POST['del_id'];
     $section_id = implode($del_id, ',');
     //实例化
     $section = new SectionModel();
     $category = new CategoryModel();
     $article = new ArticleModel();
     $menu_items = new MenuItemModel();
     //如果单元删除成功
     if ($section->delete($section_id)) {
         //删除下属分类以及分类下属文章
         $where = array('sectionid' => array('in', $section_id));
         //删除分类
         $category->where($where)->delete();
         //删除文章
         $article->where($where)->delete();
         //删除单元后删除菜单项中的单元
         $menu_where = array('type_id' => array('in', $section_id), 'type' => 'Section');
         $menu_items->where($menu_where)->delete();
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->success('单元,菜单项以及所有相关文章类别已删除~~~~');
     } else {
         $this->assign('jumpUrl', __URL__ . '/index');
         $this->error('删除失败~~~~' . $category->getError());
     }
 }
Пример #8
0
 /**
  * 公用头部 方法
  */
 function head()
 {
     //读取前台配置文件,因为该文件没有包含进配置文件,使用快速方法 F
     $config = F('front_info.inc', '', './Config/');
     $this->assign('config', $config);
     //获得滚动文章的列表
     $Articles = new ArticleModel();
     $art_where = array("published" => array('eq', 1));
     $list = $Articles->where($art_where)->order("id desc")->limit($config['rollnum'])->select();
     $this->assign('roll_arts', $list);
 }