1.页面退出功能的实现
1.在导航页面的html文件中 给a链接中的get请求传一个action参数
<li><a href="/admin/login.php?action=logout"><i class="fa fa-sign-out"></i>退出</a></li>
2.清楚登陆标识
//退出
if($_SERVER['REQUEST_METHOD']==='GET' && isset($_GET['action']) && $_GET['action']=='layout'){
//删除登陆标识
unset($_SESSION['current_logged_user']);
}
2.文章列表页面的实现
1.列表数据的呈现
(1)html页面通过遍历拿到数据
<?php foreach($posts as $item):?>
<tr>
<td class="text-center"><input type="checkbox"></td>
<td><?php echo $item['title'];?></td>
<!-- 当输出判断或者业务逻辑过于复杂时,不建议直接写在混编的位置:建议写一个函数 -->
<td><?php echo $item['user_name'];?></td>
<td><?php echo $item['category_name'];?></td>
<td class="text-center"><?php echo convert_date($item['created']);?></td>
<td class="text-center"><?php echo convert_status($item['status']);?></td>
<td class="text-center">
<a href="javascript:;" class="btn btn-default btn-xs">编辑</a>
<a href="/admin/posts-delete.php?id=<?php echo $item['id'];?>">删除</a>
</td>
</tr>
<?php endforeach?>
(2)php连接数据库端口
方案一:
缺点:需要多次链接数据库
$posts=xiu_fetch_all("SELECT * FROM posts");
//根据之前查询到的id再去对应的数据库中查作者和分类的名称
//从数据库查询名
function get_category($category_id){
return(xiu_fetch_one("SELECT name from categories WHERE id={$category_id}"))['name'];
}
//从数据库查询分类名称
function get_user($user_id){
return(xiu_fetch_one("SELECT name from users WHERE id={$user_id}"))['nickname'];
}
php中输出
<td><?php echo get_category($item['user_name']);?></td>
<td><?php echo get_user($item['