Skip to content

Commit 2884c38

Browse files
committed
Codeigniter-Blog v2.2 Updated style of partial pages, added comment reply function and added pagination function for backstage
1 parent d0ca341 commit 2884c38

9 files changed

Lines changed: 165 additions & 25 deletions

File tree

application/controllers/admin/Admin.php

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public function __construct()
88
parent::__construct();
99
$this->load->model('admin_model');
1010
$this->load->helper('url');
11+
$this->load->library('pagination');
1112
}
1213

1314
/**
@@ -102,28 +103,90 @@ public function logout()//登出功能
102103
*/
103104
public function article()
104105
{
105-
$data['rows'] = $this->admin_model->article();
106+
$config['base_url'] = 'http://cc.com:89/admin/admin/article';
107+
$config['total_rows'] = $this->db->get("article")->num_rows();
108+
$config['per_page'] = 8;
109+
$config['num_links'] = 100;
110+
$this->pagination->initialize($config);
111+
112+
$data['rows'] = $this->admin_model->article($config);
106113
$this->load->view('admin/article', $data);
107114
}
108115

109116
public function diaries()
110117
{
111-
$data['rows'] = $this->admin_model->diaries();
118+
$config['base_url'] = 'http://cc.com:89/admin/admin/diaries';
119+
$config['total_rows'] = $this->db->get("diaries")->num_rows();
120+
$config['per_page'] = 8;
121+
$config['num_links'] = 100;
122+
$this->pagination->initialize($config);
123+
124+
$data['rows'] = $this->admin_model->diaries($config);
112125
$this->load->view('admin/diaries', $data);
113126
}
114127

115128
public function tweets()
116129
{
117-
$data['rows'] = $this->admin_model->tweets();
130+
$config['base_url'] = 'http://cc.com:89/admin/admin/tweets';
131+
$config['total_rows'] = $this->db->get("tweets")->num_rows();
132+
$config['per_page'] = 10;
133+
$config['num_links'] = 100;
134+
$this->pagination->initialize($config);
135+
136+
$data['rows'] = $this->admin_model->tweets($config);
118137
$this->load->view('admin/tweets', $data);
119138
}
120139

121140
public function guestbook()
122141
{
123-
$data['rows'] = $this->admin_model->guestbook();
142+
$config['base_url'] = 'http://cc.com:89/admin/admin/guestbook';
143+
$config['total_rows'] = $this->db->get("guestbook")->num_rows();
144+
$config['per_page'] = 8;
145+
$config['num_links'] = 100;
146+
$this->pagination->initialize($config);
147+
148+
$data['rows'] = $this->admin_model->guestbook($config);
124149
$this->load->view('admin/guestbook', $data);
125150
}
126151

152+
public function reply($id)
153+
{
154+
if ($_SESSION['logged_in'] == TRUE)
155+
{
156+
$data['rows'] = $this->admin_model->reply($id);
157+
$this->load->view('admin/reply', $data);
158+
}else{
159+
redirect('admin/admin/login');
160+
}
161+
}
162+
163+
public function reply_store()
164+
{
165+
if ($_SESSION['logged_in'] == TRUE)
166+
{
167+
if ($_POST != True)
168+
{
169+
$this->load->view('admin/reply');
170+
}
171+
elseif (
172+
$this->input->post('name') &&
173+
$this->input->post('content') &&
174+
$this->input->post('date') != null
175+
){
176+
$name = $this->input->post('name');
177+
$content = $this->input->post('content');
178+
$date = $this->input->post('date');
179+
180+
$result = $this->admin_model->reply_store($name, $content, $date);
181+
$this->load->view('admin/reply', $result);
182+
}else{
183+
$this->load->view('admin/reply');
184+
}
185+
}else{
186+
redirect('admin/admin/login');
187+
}
188+
}
189+
127190
public function photos()
128191
{
129192
$data['rows'] = $this->admin_model->photos();

application/models/Admin_model.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,54 @@ private function verify_password_hash($password, $hash)
7373
/**
7474
* 文本显示模块
7575
*/
76-
public function article()
76+
public function article($config)
7777
{
78-
$data = $this->db->from('article')->order_by('id', 'desc')->get();
78+
$data = $this->db->order_by('id', 'desc')->get('article', $config['per_page'], $this->uri->segment(4));
7979
return $data->result();
8080
}
8181

82-
public function diaries()
82+
public function diaries($config)
8383
{
84-
$data = $this->db->from('diaries')->order_by('id', 'desc')->get();
84+
$data = $this->db->order_by('id', 'desc')->get('diaries', $config['per_page'], $this->uri->segment(4));
8585
return $data->result_array();
8686
}
8787

88-
public function tweets()
88+
public function tweets($config)
8989
{
90-
$data = $this->db->from('tweets')->order_by('id', 'desc')->get();
90+
$data = $this->db->order_by('id', 'desc')->get('tweets', $config['per_page'], $this->uri->segment(4));
9191
return $data->result_array();
9292
}
9393

94-
public function guestbook()
94+
public function guestbook($config)
9595
{
96-
$data = $this->db->from('guestbook')->order_by('id', 'desc')->get();
96+
$data = $this->db->get('guestbook', $config['per_page'], $this->uri->segment(4));
9797
return $data->result_array();
9898
}
9999

100+
public function reply($id)
101+
{
102+
$data = $this->db->from('guestbook')->where('id=', $id)->get();
103+
return $data->result()[0];
104+
}
105+
106+
public function reply_store($name, $content, $date)
107+
{
108+
if ($this->db->insert('guestbook',array(
109+
110+
'name' => $name,
111+
'content' => $content,
112+
'date' => $date
113+
114+
) )){
115+
116+
return $this->db->insert_id() && redirect('admin/admin/guestbook');
117+
118+
}else{
119+
log_message ('error', 'register error-->' . $this->db->last_query());
120+
return false;
121+
}
122+
}
123+
100124
public function photos()
101125
{
102126

application/models/Home_model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function article($id)
2626

2727
public function tweets($config)
2828
{
29-
$query = $this->db->get('tweets', $config['per_page'], $this->uri->segment(3));
29+
$query = $this->db->order_by('id', 'desc')->get('tweets', $config['per_page'], $this->uri->segment(3));
3030
return $query->result_array();
3131
}
3232

application/views/admin/article.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
<!--left end-->

application/views/admin/diaries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
<a><?php echo anchor('admin/admin/delete_diaries/'.$row['id'],'删除日记')?></a>
6161
</div>
6262
<div class="clear"></div>
63-
<?php endforeach;}?>
63+
<?php endforeach;}?><br />&nbsp&nbsp
64+
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
6465
</div>
6566
<!--时光 end-->
6667
</div>

application/views/admin/guestbook.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@
4444
<div class="weizi">
4545
<div class="wz_text">当前位置:首页><h1>留言板</h1></div>
4646
</div>
47-
4847
<div class="g_content">
4948
有什么想对我说的嘛?
5049
<?php if (isset($rows)) { foreach ($rows as $row):?>
51-
<h4><font color="#ff69b4"><br/>
52-
&nbsp&nbsp<?php echo $row['name']?><br/>
53-
&nbsp&nbsp<?php echo $row['content']?><br/>
54-
&nbsp&nbsp<?php echo $row['date']?>
55-
<a><?php echo anchor('admin/admin/delete_guestbook/'.$row['id'],'删除留言')?></a>
56-
</font></h4>
57-
<?php endforeach;}?>
50+
<h3>
51+
<font color="#ff69b4">
52+
<br />&nbsp&nbsp<?php echo $row['name']?>
53+
&nbsp&nbsp<?php echo $row['date']?><br />
54+
&nbsp&nbsp<?php echo $row['content']?><br /><br />
55+
<a><?php echo anchor('admin/admin/delete_guestbook/'.$row['id'],'删除留言')?></a>
56+
<a style="padding-left: 5%;">
57+
<?php echo anchor('admin/admin/reply/'.$row['id'], 'Reply');?>
58+
</a><br /><br />
59+
</font>
60+
</h3>
61+
<?php endforeach;}?><br />&nbsp&nbsp
62+
<font color="blue" size="4"><?php echo $this->pagination->create_links();?></font>
5863
</div>
5964
</div>
6065
<!--end left -->

application/views/admin/reply.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
defined('BASEPATH') OR exit('No direct script access allowed');
3+
?>
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="UTF-8">
9+
<title>回复留言</title>
10+
<link rel="stylesheet" href="<?php echo base_url();?>static/admin/css/article.css">
11+
<link rel="icon" href="<?php echo base_url();?>static/images/favicon/favicon.ico">
12+
</head>
13+
14+
<body>
15+
<div class="wrap">
16+
<div class="container">
17+
<h1 style="margin: 0; text-align: center;"><font>你好,旅行者。 👋</font></h1>
18+
19+
<form action="<?php echo base_url('admin/admin/reply_store');?>" method="post">
20+
<label><input type="text" name="name" value="Nova &nbsp&nbsp&nbsp@<?php echo $rows->name;?>" maxlength="15" placeholder="评论者" required/></label>
21+
22+
<textarea class="add" type="text" name="content" maxlength="255" placeholder="想想看说什么好呢?" required></textarea>
23+
24+
<label><input type="text" name="date" readonly="readonly" value="<?php echo date('Y-m-d H:i:s');?>"/></label>
25+
26+
<input type="submit" name="submit" value="ヽ( =ノωヽ=)ノstart"/>
27+
28+
<p class="change_link" style="text-align: center"></p>
29+
</form>
30+
31+
</div>
32+
<ul>
33+
<li></li>
34+
<li></li>
35+
<li></li>
36+
<li></li>
37+
<li></li>
38+
<li></li>
39+
<li></li>
40+
<li></li>
41+
<li></li>
42+
<li></li>
43+
</ul>
44+
</div>
45+
</body>
46+
</html>

application/views/admin/tweets.php

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

application/views/message.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
defined('BASEPATH') OR exit('No direct script access allowed');
33
?>
4-
54
<!DOCTYPE html>
65
<html lang="en">
76
<head>

0 commit comments

Comments
 (0)