总结:
该日课程 模拟了数据在各个界面中的展示,传递的用法。
header界面与footer界面:
放在common文件夹中作为公共界面
实例
<?php $cates = [ ['cate_id'=>1,'name'=>'gc','alias'=>'国产好剧'], ['cate_id'=>2,'name'=>'om','alias'=>'欧美猛片'], ['cate_id'=>3,'name'=>'rh','alias'=>'日韩新片'], ]; $movies = [ ['mov_id'=>1,'cate_id'=>'1','name'=>'倚天屠龙记','detail'=>'武侠神剧,满分推荐'], ['mov_id'=>2,'cate_id'=>'1','name'=>'天龙八部','detail'=>'武侠神剧,满分推荐'], ['mov_id'=>3,'cate_id'=>'1','name'=>'神雕侠侣','detail'=>'武侠神剧,满分推荐'], ['mov_id'=>4,'cate_id'=>'2','name'=>'钢铁侠','detail'=>'一般般,凑合看吧'], ['mov_id'=>5,'cate_id'=>'2','name'=>'妇联','detail'=>'一般般,凑合看吧'], ['mov_id'=>6,'cate_id'=>'2','name'=>'蜘蛛侠','detail'=>'一般般,凑合看吧'], ['mov_id'=>7,'cate_id'=>'3','name'=>'***鬼子','detail'=>'***,千万别看'], ['mov_id'=>8,'cate_id'=>'3','name'=>'高丽棒子','detail'=>'***,千万别看'], ['mov_id'=>9,'cate_id'=>'3','name'=>'不要脸','detail'=>'***,千万别看'] ]; $system = [ 'sys_id' =>1,'title'=>'私人影院','desc'=>'收集世界最新最全的影视资源','key'=>'国产,欧美,日韩','code'=>'小陈先生' ]; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首页</title> <link rel="stylesheet" href="static/css/header.css"> </head> <body> <div class="header"> <div class="content"> <ul class="nav"> <li class="item"><a href ="index.php">首页</a></li> <?php foreach($cates as $cate){?> <li class="item"><a href ="list.php?cate_id=<?=$cate['cate_id']?>"><?php echo $cate['alias'] ?></a></li> <?php }?> </ul> </div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首页</title> <link rel="stylesheet" href="static/css/footer.css"> </head> <body> <div class="footer"> <div class="content"> <p> <a href="">© PHP中文网版权所有</a> | <a href="">0551-88889999</a> | <a href="">皖ICP2016098801-1</a> </p> </div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
list界面:
利用require 引入common中的公共文件
点击header中的a标签会跳转进入list界面:
实例
<?php require __DIR__."/common/header.php"; $cate_id = intval($_GET['cate_id']); foreach ($cates as $cate){ if($cate_id==$cate['cate_id']) { echo "<h2>{$cate['alias']}</h2>"; echo "<ol>"; foreach ($movies as $movie){ if($cate_id==$movie['cate_id']){ echo "<li><a href='detail.php?mov_id=".$movie["mov_id"]."'> {$movie['name']}</a> </li>"; } } echo "</ol>"; } } require __DIR__."/common/footer.php";
运行实例 »
点击 "运行实例" 按钮查看在线实例
Index界面:
双foreach利用if判断 显示出两个数组中的所有数据
实例
<?php require __DIR__."/common/header.php"; foreach ($cates as $cate){ echo "<h2>{$cate['alias']}</h2>"; echo "<ol>"; foreach ($movies as $movie){ if($cate['cate_id']==$movie['cate_id']){ echo "<li><a href='detail.php?mov_id=".$movie["mov_id"]."'> {$movie['name']}</a> </li>"; } } echo "</ol>"; } require __DIR__."/common/footer.php";
运行实例 »
点击 "运行实例" 按钮查看在线实例
detail界面:
点击index中 电影名称的a标签会跳转进入
list同理
实例
<?php require __DIR__."/common/header.php"; $movie_id = intval($_GET["mov_id"]); foreach ($movies as $movie){ if($movie_id==$movie['mov_id']){ echo "<h2>{$movie["name"]}</h2>"; echo $movie["detail"]; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例