Skip to content

Commit 24f2550

Browse files
committed
Codeigniter-Blog v2.1 Added pagination function, Improved css, Compressed image size
1 parent 8a8206f commit 24f2550

18 files changed

Lines changed: 66 additions & 37 deletions

File tree

application/controllers/Home.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function index()//index公共函数,主页
2020
$this->load->view('home', $data);//加载视图
2121
}
2222

23-
public function article($id)
23+
public function article($id)//文章详情页
2424
{
2525
$data['rows'] = $this->home_model->article($id);
2626
$this->load->view('article', $data);
@@ -33,13 +33,25 @@ public function about()
3333

3434
public function tweets()
3535
{
36-
$data['rows'] = $this->home_model->tweets();
36+
$config['base_url']='http://cc.com:89/home/tweets';
37+
$config['total_rows']=$this->db->get("tweets")->num_rows();
38+
$config['per_page']=10;
39+
$config['num_links']=100;
40+
$this->pagination->initialize($config);
41+
42+
$data['rows'] = $this->home_model->tweets($config);
3743
$this->load->view('tweets', $data);
3844
}
3945

4046
public function diaries()
4147
{
42-
$data['rows'] = $this->home_model->diaries();
48+
$config['base_url']='http://cc.com:89/home/diaries';
49+
$config['total_rows']=$this->db->get("diaries")->num_rows();
50+
$config['per_page']=8;
51+
$config['num_links']=100;
52+
$this->pagination->initialize($config);
53+
54+
$data['rows'] = $this->home_model->diaries($config);
4355
$this->load->view('diaries', $data);
4456
}
4557

@@ -50,13 +62,25 @@ public function photos()
5062

5163
public function learn()
5264
{
53-
$data['rows'] = $this->home_model->learn();
65+
$config['base_url']='http://cc.com:89/home/learn';
66+
$config['total_rows']=$this->db->get("article")->num_rows();
67+
$config['per_page']=8;
68+
$config['num_links']=100;
69+
$this->pagination->initialize($config);
70+
71+
$data['rows'] = $this->home_model->learn($config);
5472
$this->load->view('learn', $data);
5573
}
5674

5775
public function guestbook()
5876
{
59-
$data['rows'] = $this->home_model->guestbook();
77+
$config['base_url']='http://cc.com:89/home/guestbook';
78+
$config['total_rows']=$this->db->get("guestbook")->num_rows();
79+
$config['per_page']=8;
80+
$config['num_links']=100;
81+
$this->pagination->initialize($config);
82+
83+
$data['rows'] = $this->home_model->guestbook($config);
6084
$this->load->view('guestbook', $data);
6185
}
6286

@@ -68,8 +92,8 @@ public function message()//留言功能
6892
}
6993
elseif ($this->input->post('name') && $this->input->post('content') && $this->input->post('date') != null)
7094
{
71-
$name = $this->input->post('name');
72-
$content = $this->input->post('content');
95+
$name = $this->security->xss_clean($this->input->post('name'));//XSS攻击防护
96+
$content = $this->security->xss_clean($this->input->post('content'));
7397
$date = $this->input->post('date');
7498
$result = $this->home_model->message($name, $content, $date);
7599

application/controllers/admin/Admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function login()
5454

5555
}else{
5656

57-
$username = $this->input->post('username');
58-
$password = $this->input->post('password');
57+
$username = $this->security->xss_clean($this->input->post('username'));//XSS攻击防护
58+
$password = $this->security->xss_clean($this->input->post('password'));
5959

6060
if ($this->admin_model->login($username, $password))
6161
{

application/models/Home_model.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function home()
1414
//$query = $this->db->query('select * from article order by id desc limit 0,5');//加载数据表
1515

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

@@ -24,27 +24,27 @@ public function article($id)
2424
return $data->result()[0];
2525
}
2626

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

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

39-
public function learn()
39+
public function learn($config)
4040
{
41-
$query = $this->db->get('article');
42-
return $query->result_array();//多结果标准查询(数组形式)
41+
$query = $this->db->get('article', $config['per_page'],$this->uri->segment(3));
42+
return $query->result_array();
4343
}
4444

45-
public function guestbook()
45+
public function guestbook($config)
4646
{
47-
$query = $this->db->get('guestbook');
47+
$query = $this->db->get('guestbook', $config['per_page'],$this->uri->segment(3));
4848
return $query->result_array();
4949
}
5050

application/views/admin/guestbook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<!--content start-->
3939
<div id="content">
4040
<!--left-->
41-
<div class="left" id="guestbook">
41+
<div class="left" id="c_left">
4242
<div class="weizi">
4343
<div class="wz_text">当前位置:首页><h1>留言板</h1></div>
4444
</div>
@@ -47,9 +47,9 @@
4747
有什么想对我说的嘛?
4848
<?php if (isset($rows)) { foreach ($rows as $row):?>
4949
<h4><font color="#ff69b4"><br/>
50-
<?php echo $row['name']?><br/>
51-
<?php echo $row['content']?><br/>
52-
<?php echo $row['date']?>
50+
&nbsp&nbsp<?php echo $row['name']?><br/>
51+
&nbsp&nbsp<?php echo $row['content']?><br/>
52+
&nbsp&nbsp<?php echo $row['date']?>
5353
<a><?php echo anchor('admin/admin/delete_guestbook/'.$row['id'],'删除留言')?></a>
5454
</font></h4>
5555
<?php endforeach;}?>

application/views/diaries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
<?php echo $row['date']?>
5959
</div>
6060
<div class="clear"></div>
61-
<?php endforeach;}?>
61+
<?php endforeach;}?><br />&nbsp&nbsp
62+
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
6263
</div>
6364
<!--时光 end-->
6465
</div>

application/views/guestbook.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<!--content start-->
4141
<div id="content">
4242
<!--left-->
43-
<div class="left" id="guestbook">
43+
<div class="left" id="c_left">
4444
<div class="weizi">
4545
<div class="wz_text">当前位置:首页><h1>留言板</h1></div>
4646
</div>
@@ -49,13 +49,15 @@
4949
有什么想对我说的嘛?&nbsp&nbsp<a href="<?php echo base_url('home/message');?>">给我留言</a>
5050
<?php if (isset($rows)) { foreach ($rows as $row):?>
5151
<h4><font color="#ff69b4"><br/>
52-
<?php echo $row['name']?><br/>
53-
<?php echo $row['content']?><br/>
54-
<?php echo $row['date']?>
52+
&nbsp&nbsp<?php echo $row['name']?><br/>
53+
&nbsp&nbsp<?php echo $row['content']?><br/>
54+
&nbsp&nbsp<?php echo $row['date']?>
5555
</font></h4>
56-
<?php endforeach;}?>
56+
<?php endforeach;}?><br />&nbsp&nbsp
57+
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
5758
</div>
5859
</div>
60+
5961
<!--end left -->
6062
<!--right-->
6163
<div class="right" id="c_right">

application/views/home.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<table bgcolor="#FFFFFF">
2626
<tr>
2727
<td>
28-
<input type=text name=keyword size=11 value="">
28+
<input type=text name=keyword size=11 value="" placeholder="输入关键字">
2929
<input type=hidden name=ie value=UTF8>
3030
<input type=hidden name=oe value=UTF8>
3131
<input type=hidden name=hl value=zh-CN>
@@ -135,7 +135,7 @@
135135
<!--content end-->
136136
<!--footer start-->
137137
<div id="footer">
138-
<p>Design by:Nova <?php echo date('Y-m-d');?></p>
138+
<p>Design by:Nova &nbsp&nbsp<?php echo date('Y-m-d');?><br />Development based on CodeIgniter</p>
139139
</div>
140140
<script type="text/javascript" src="<?php echo base_url();?>static/js/jquery1.42.min.js"></script>
141141
<script type="text/javascript" src="<?php echo base_url();?>static/js/jquery.SuperSlide.2.1.1.js"></script>

application/views/learn.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
<div class="clear"></div>
6464
</dl>
6565
</div>
66-
<!--wz end--><?php endforeach;}?>
66+
<!--wz end--><?php endforeach;}?><br />&nbsp&nbsp
67+
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
6768
</div>
6869
</div>
6970
<!--end left -->

application/views/tweets.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
</div>
4848
<span class="dateview"><?php echo $row['date']?></span>
4949
</ul>
50-
<?php endforeach;}?>
50+
<?php endforeach;}?><br />&nbsp&nbsp
51+
<font color="blue" size="5"><?php echo $this->pagination->create_links();?></font>
5152
</div>
5253
<!--content end-->
5354
<!--footer-->

static/css/background.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#home {
1+
#home {
22
margin: 40px;
33
background-color: #E3D8BC;
44
background-image: url(../images/bg.png);
@@ -38,7 +38,7 @@
3838
color: #444;
3939
}
4040

41-
#learnjourney {
41+
#learnjourney {
4242
margin: 40px;
4343
background-color: #E4E0D5;
4444
background-image: url(../images/InkCat.jpg);
@@ -49,7 +49,7 @@
4949
color: #444;
5050
}
5151

52-
#guestbook-color {
52+
#guestbook-color {
5353
margin: 40px;
5454
background-image: url(../images/Alice.jpg);
5555
background-size: 100% 100%;

0 commit comments

Comments
 (0)