News.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\school\model\content\Newscategory;
use think\Db;
class News extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = 'default';
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$newsTitle = Db::name('news_category')->field('title,id')->where('flag','index')->where(['school_id' => $this->school_id,'status'=>["<>",'lock']])->limit(3)->select();
$this->assign('tabTitle',$newsTitle);
}
/**
* @return string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* 新闻列表
*/
public function index()
{
$param = $this->request->param();
$list = Db::name("news_content")->where('school_id',$this->school_id)->where(["category_id"=>$param['category_id']])->paginate(10,false,["query"=>request()->param()]);
$this->assign("list",$list);
$this->assign("title", $param['title']);
return $this->view->fetch();
}
/**
* @return string
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* 新闻详情
*/
public function news_detail()
{
$param = $this->request->param();
Db::name("news_content")->where(["id"=>$param['id']])->setInc("visit_count");
$info = Db::name("news_content")->where(["id"=>$param['id']])->find();
$this->assign("info",$info);
$this->assign("title",$param['title']);
return $this->view->fetch();
}
}