Correction status:Uncorrected
Teacher's comments:
实现模块化,重复数据做成公共模板,提高访问效率;
案例
1列表模板页
<?php // 加载头文件 include __DIR__."/public/include/header.php"; //遍历栏目和电影名称 $cate_id=$_GET['cate_id']; foreach ($cates as $cate) { if($cate['cate_id']==$cate_id){ 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>'; } } // 加载尾部文件 include __DIR__."/public/include/footer.php"; ?>
点击 "运行实例" 按钮查看在线实例
2详情模板页
<?php // 加载头文件 include __DIR__."/public/include/header.php"; //详情页 $mov_id=$_GET['mov_id']; foreach($movies as $movie){ if($movie['mov_id']==$mov_id){ echo "<h3>{$movie['name']}</h3>"; echo '<img src="public/static/images/'.$movie['image'].'" alt="" width="400">'; echo "<p style='text-indent: 2em'>{$movie['detail']}</p>"; } } // 加载尾部文件 include __DIR__."/public/include/footer.php"; ?>
点击 "运行实例" 按钮查看在线实例