Skip to content

Commit 885c08d

Browse files
committed
CodeIgniter-Blog v2.4.1 Optimized website UI, Added the article category section.
1 parent 36aa13d commit 885c08d

14 files changed

Lines changed: 130 additions & 54 deletions

File tree

application/controllers/Home.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ public function __construct()
1414

1515
public function index()//index公共函数,主页
1616
{
17-
$data['rows'] = $this->home_model->home();//调用home_model模型home类
17+
$config['base_url'] = 'http://codeigniter-3.1.11.bb/home/index';//输出分页链接
18+
$config['total_rows'] = $this->db->get("article")->num_rows();
19+
$config['per_page'] = 8;
20+
$config['num_links'] = 100;
21+
$this->pagination->initialize($config);
22+
23+
$data['rows'] = $this->home_model->home($config);//调用home_model模型home类
1824
$this->load->view('home', $data);//加载视图
1925
}
2026

@@ -31,7 +37,7 @@ public function about()//关于页面
3137

3238
public function tweets()
3339
{
34-
$config['base_url'] = 'http://codeigniter-3.1.11.bb/home/tweets';//输出分页链接
40+
$config['base_url'] = 'http://codeigniter-3.1.11.bb/home/tweets';
3541
$config['total_rows'] = $this->db->get("tweets")->num_rows();
3642
$config['per_page'] = 10;
3743
$config['num_links'] = 100;
@@ -64,16 +70,23 @@ public function photos()
6470
$this->load->view('photos');
6571
}
6672

67-
public function learn()
73+
public function category()
6874
{
69-
$config['base_url'] = 'http://codeigniter-3.1.11.bb/home/learn';
75+
$data['rows'] = $this->home_model->category();
76+
$this->load->view('category', $data);
77+
}
78+
79+
public function category_details($type)
80+
{
81+
$config['base_url'] = 'http://codeigniter-3.1.11.bb/home/category_details/' . $type;
7082
$config['total_rows'] = $this->db->get("article")->num_rows();
7183
$config['per_page'] = 8;
7284
$config['num_links'] = 100;
85+
7386
$this->pagination->initialize($config);
7487

75-
$data['rows'] = $this->home_model->learn($config);
76-
$this->load->view('learn', $data);
88+
$data['rows'] = $this->home_model->category_details($config, $type);
89+
$this->load->view('category_details', $data);
7790
}
7891

7992
public function guestbook()

application/models/Home_model.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public function __construct()
99
$this->load->database();//加载数据库
1010
}
1111

12-
public function home()
12+
public function home($config)
1313
{
1414
//$query = $this->db->query('select * from article order by id desc limit 0,8');//加载数据表
1515

1616
//调用article表,按id倒序排列并显示8条数据
17-
$data = $this->db->from('article')->order_by('id', 'desc')->limit(8)->get();
18-
return $data->result();
17+
$data = $this->db->order_by('id', 'desc')->get('article', $config['per_page'], $this->uri->segment(3));
18+
return $data->result();//单结果标准查询(对象形式)
1919
}
2020

2121
public function article($id)
@@ -26,14 +26,14 @@ public function article($id)
2626

2727
public function tweets($config)
2828
{
29-
$query = $this->db->order_by('id', 'desc')->get('tweets', $config['per_page'], $this->uri->segment(3));
30-
return $query->result_array();
29+
$data = $this->db->order_by('id', 'desc')->get('tweets', $config['per_page'], $this->uri->segment(3));
30+
return $data->result_array();//单结果标准查询(数组形式)
3131
}
3232

3333
public function diaries($config)
3434
{
35-
$query = $this->db->get('diaries', $config['per_page'], $this->uri->segment(3));
36-
return $query->result_array();
35+
$data = $this->db->get('diaries', $config['per_page'], $this->uri->segment(3));
36+
return $data->result_array();
3737
}
3838

3939
public function diaries_details($id)//日记详情
@@ -42,16 +42,22 @@ public function diaries_details($id)//日记详情
4242
return $data->result_array()[0];
4343
}
4444

45-
public function learn($config)
45+
public function category()
46+
{
47+
$data = $this->db->group_by('type')->get('article');
48+
return $data->result();
49+
}
50+
51+
public function category_details($config, $type)//分类详情
4652
{
47-
$query = $this->db->get('article', $config['per_page'], $this->uri->segment(3));
48-
return $query->result_array();
53+
$data = $this->db->where('type=', $type)->get('article', $config['per_page'], $this->uri->segment(4));
54+
return $data->result();
4955
}
5056

5157
public function guestbook($config)
5258
{
53-
$query = $this->db->get('guestbook', $config['per_page'], $this->uri->segment(3));
54-
return $query->result_array();
59+
$data = $this->db->get('guestbook', $config['per_page'], $this->uri->segment(3));
60+
return $data->result_array();
5561
}
5662

5763
public function message($name, $content, $date)

application/views/admin/article.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<span class="left author">Nova</span>
4040
<span class="left sj">时间:<?php echo $row->date;?></span>
4141
<span class="left fl">分类:<?php echo $row->type;?></span>
42-
<a><?php echo anchor('admin/admin/edit_article/'.$row->id,'更新文章')?></a>
43-
<a><?php echo anchor('admin/admin/delete_article/'.$row->id,'删除文章')?></a>
42+
<a><?php echo anchor('admin/admin/edit_article/' . $row->id,'更新文章')?></a>
43+
<a><?php echo anchor('admin/admin/delete_article/' . $row->id,'删除文章')?></a>
4444
<div class="clear"></div>
4545
</p>
4646
</dd>

application/views/admin/diaries.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
</div>
4141
<a style="padding-left: 3%"><?php echo $row['date']?></a>
4242
<a style="padding-left: 45%;">
43-
<?php echo anchor('admin/admin/edit_diaries/'.$row['id'],'更新日记')?>
43+
<?php echo anchor('admin/admin/edit_diaries/' . $row['id'],'更新日记')?>
4444
</a>
4545
<a style="padding-left: 5%;">
46-
<?php echo anchor('admin/admin/delete_diaries/'.$row['id'],'删除日记')?>
46+
<?php echo anchor('admin/admin/delete_diaries/' . $row['id'],'删除日记')?>
4747
</a>
4848
<div class="clear"></div>
4949
</div>

application/views/admin/edit_article.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="wrap">
1616
<div class="container">
1717
<h1 style="margin: 0; text-align: center;"><font>Hi, Nova 👋</font></h1>
18-
<form action="<?php echo base_url('admin/admin/update_article/'.$article->id);?>" method="post">
18+
<form action="<?php echo base_url('admin/admin/update_article/' . $article->id);?>" method="post">
1919

2020
<label><input type="text" name="title" placeholder="title" value="<?php echo $article->title;?>"/></label>
2121

application/views/admin/edit_diaries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="wrap">
1616
<div class="container">
1717
<h1 style="margin: 0; text-align: center;"><font>Hi, Nova 👋</font></h1>
18-
<form action="<?php echo base_url('admin/admin/update_diaries/'.$diaries->id);?>" method="post">
18+
<form action="<?php echo base_url('admin/admin/update_diaries/' . $diaries->id);?>" method="post">
1919

2020
<textarea class="add" type="text" name="content" placeholder="content"><?php echo $diaries->content?></textarea>
2121

application/views/admin/edit_tweets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="wrap">
1616
<div class="container">
1717
<h1 style="margin: 0; text-align: center;"><font>Hi, Nova 👋</font></h1>
18-
<form action="<?php echo base_url('admin/admin/update_tweets/'.$tweets->id);?>" method="post">
18+
<form action="<?php echo base_url('admin/admin/update_tweets/' . $tweets->id);?>" method="post">
1919

2020
<textarea class="add" type="text" name="content" placeholder="content"><?php echo $tweets->content?></textarea>
2121

application/views/admin/guestbook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
<br />&nbsp&nbsp<?php echo $row['name']?>
3737
&nbsp&nbsp&nbsp&nbsp<?php echo $row['date']?><br />
3838
&nbsp&nbsp<?php echo $row['content']?><br /><br />
39-
<a><?php echo anchor('admin/admin/delete_guestbook/'.$row['id'],'删除留言')?></a>
39+
<a><?php echo anchor('admin/admin/delete_guestbook/' . $row['id'],'删除留言')?></a>
4040
<a style="padding-left: 5%;">
41-
<?php echo anchor('admin/admin/reply/'.$row['id'], 'Reply');?>
41+
<?php echo anchor('admin/admin/reply/' . $row['id'], 'Reply');?>
4242
</a><br /><br />
4343
</font>
4444
</h3>

application/views/admin/tweets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<ul class="say_box">
3131
<div class="sy">
3232
<p><?php echo $row['content']?></p>
33-
<a><?php echo anchor('admin/admin/edit_tweets/'.$row['id'],'更新说说')?></a>
34-
<a><?php echo anchor('admin/admin/delete_tweets/'.$row['id'],'删除说说')?></a>
33+
<a><?php echo anchor('admin/admin/edit_tweets/' . $row['id'],'更新说说')?></a>
34+
<a><?php echo anchor('admin/admin/delete_tweets/' . $row['id'],'删除说说')?></a>
3535
</div>
3636
<span class="dateview"><?php echo $row['date']?></span>
3737
</ul>
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<html lang="zh-CN">
66
<head>
77
<meta charset="UTF-8">
8-
<title>Nova's blog - 学无止境</title>
8+
<title>Nova's blog - 文章分类</title>
99
<meta name="msvalidate.01" content="" />
1010
<meta name="baidu-site-verification" content="" />
1111
<meta name="author" content="LunaNova">
@@ -26,31 +26,20 @@
2626
<!--left-->
2727
<div class="left" id="learn">
2828
<div class="weizi">
29-
<div class="wz_text">当前位置:首页><h1>学无止境</h1></div>
29+
<div class="wz_text">当前位置:首页><h1>文章分类</h1></div>
3030
</div>
3131
<div class="content_text">
3232
<!--wz--><?php if (isset($rows)) { foreach ($rows as $row):?>
3333
<div class="wz">
34-
<h3><?php echo $row['title'];?></h3>
35-
<dl>
36-
<dt><img src="<?php echo base_url();?>static/images/s2.jpg" width="200" height="123" alt="文章图片"></dt>
37-
<dd>
38-
<p class="dd_text_1"><?php echo $row['content'];?></p>
39-
<p class="dd_text_2">
40-
<span class="left author">Nova</span>
41-
<span class="left sj">时间:<?php echo $row['date'];?></span>
42-
<span class="left fl">分类:<?php echo $row['type'];?></span>
43-
<span class="left yd">
44-
<?php echo anchor('home/article/' . $row['id'] .'-'. str_replace(' ', '-', $row['title']),'阅读全文','class="ReadMore"')?>
45-
</span>
46-
<div class="clear"></div>
47-
</p>
48-
</dd>
49-
<div class="clear"></div>
50-
</dl>
34+
<h3>
35+
<span class="left fl">&nbsp&nbsp类别:<?php echo $row->type;?>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</span>
36+
<span class="left yd">
37+
<?php echo anchor('home/category_details/' . $row->type,'点击阅读','class="ReadMore"')?>
38+
</span>
39+
</h3>
40+
<br />
5141
</div>
52-
<!--wz end--><?php endforeach;}?><br />&nbsp&nbsp
53-
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
42+
<!--wz end--><?php endforeach;}?>
5443
</div>
5544
</div>
5645
<!--end left -->

0 commit comments

Comments
 (0)