Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:咱们现在是在学习阶段 , 写简单点更好, 代码越短, bug越少... 只要能实现所要求的功能即可
index内容的核心代码
<ul class="list-group list-group-flush">
<?php foreach ($dms as $v) : ?>
<li class="list-group-item">
<?php foreach ($category as $cate) : ?>
<?php if ($v['cid'] === $cate['id']) : ?>
<a href="<?php echo $cate['url'] ?>"><?php echo $cate['name'] ?></a>
<?php endif; ?>
<?php endforeach; ?>
<a href="show.php?id=<?php echo $v['id'] ?>"><?php echo $v['title'] ?></a>
<span><?php echo $v['filesize'] ?></span>
</li>
<?php endforeach; ?>
</ul>
首页内容的重点是使用了foreach嵌套循环出的内容,因为我们的动态数据不是从数据库中来,所以有一丝小麻烦要做到文章分类(也就是cid显示中文)
header部分循环导航也没什么可以写的就是简简单单的循环
$cid = intval($_GET['cid']);
//定义函数用来列出分类资源
/**
* getCidDms获取分页动漫列表
* $cid 分类ID
* $dms 资源列表
* Return array类型 资源
*/
function getCidDms($cid,$dms){
foreach($dms as $dm){
if ($dm['cid'] === $cid) {
$ciddms[]=$dm;
}
}
return $ciddms;
}
function getCidName($cid,$category){
foreach($category as $v){
if($cid === $v['id']){
$cname = $v['name'];
}
}
return $cname;
}
$ciddms = getCidDms($cid,$dms);
$cname = getCidName($cid,$category);
在列表页面我这边实现了分类显示,分类内容以上是核心代码,封装成了简单函数
function getDm($id,$dms){
foreach($dms as $v){
if ($id === $v['id']) {
$dmactive[] = $v['title'];
$dmactive[] = $v['cid'];
}
}
return $dmactive;
}
function getCidName($cid,$category){
foreach($category as $v){
if($cid === $v['id']){
$cname = $v['name'];
}
}
return $cname;
}
$dmactive = getDm($id,$dms);
// $cname = getCidName($dmactive[1],$category);
// var_dump($cname);
$siteweb = '爱动漫网';
//栏目导航
$category=[
['id'=>1,'name'=>'新番连载','url'=>'list.php?cid=1'],
['id'=>2,'name'=>'动画合集','url'=>'list.php?cid=2'],
];
$dms=[
['id'=>1,'title'=>'[ReinForce] 街角魔族 Machikado Mazoku (BDRip 1920x1080 x264 FLAC)','filesize'=>'123.57MB','cid'=>1],
['id'=>2,'title'=>'【飞沐team】飞哥与小佛 第一季 Phineas and Ferb Season 1 (2007) (26集全)(国英双语)(1080P)[MKV]','filesize'=>'585.7MB','cid'=>2],
['id'=>3,'title'=>'[Lilith-Raws] 理科生墜入情網,故嘗試證明。/ Rikekoi [01-12][BiliBili][WEB-DL][1080p][AVC AAC][CHT][MKV]','filesize'=>'585.7MB','cid'=>1],
['id'=>4,'title'=>'食戟之灵 第一季 Shokugeki no Souma 1-24 [BD 1920x1080 HEVC 10bit][简繁内封字幕]','filesize'=>'585.7MB','cid'=>1],
];
由于本次作业是在兼职店中的空闲时间完成,所以看上去会比较简陋,但是该有的功能全部都有。只需要在config.php中添加所对应的内容即可