Correction status:Uncorrected
Teacher's comments:
视图
<!DOCTYPE html><html lang="zh-CN"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>首页 - 欧阳克个人博客</title> <meta name="keywords" content="博客,个人博客,欧阳克个人博客,PHP"/> <meta name="description" content="欧阳克是PHP中文网的讲师,愿意把知识分享给大家。" /> <link rel="stylesheet" id="twentytwelve-style-css" href="static/css/index.css" type="text/css" media="all" /> <style type="text/css" id="custom-background-css"> body.custom-background {background-color:#e6e6e6;} input.btn-default:focus,input.no-border:focus {outline:none;} input.no-border {font-size:15px;} </style> <script type="text/javascript" src="static/js/jquery.js"></script> <script type="text/javascript" src="static/js/nav.js"></script></head><body class="home blog custom-background custom-font-enabled single-author"> <div id="page" class="hfeed site"> <header id="masthead" class="site-header" role="banner"> <hgroup> <h1 class="site-title"> <a href="/" title="欧阳克个人博客" rel="home">欧阳克个人博客</a> </h1> <h2 class="site-description">欧阳克是PHP中文网的讲师,愿意把知识分享给大家。</h2> </hgroup> <nav id="site-navigation" class="main-navigation" role="navigation"> <ul class="nav-menu"> <li> <a href="/">首页</a> </li> {foreach $cat as $value} <li> <a href="?name={$value.name}">{$value.name}</a> </li> {/foreach} </ul> </nav> </header> <div id="main" class="wrapper"> <div id="primary" class="site-content"> {foreach($select as $select_v)} <div id="content" role="main"> <article> <header class="entry-header"> <h1 class="entry-title"> <a href="/details.html" title="构建Nginx和PHP镜像" rel="bookmark" >{$select_v['title']}</a> </h1> </header> <div class="entry-content">{$select_v['content']}</div> <footer class="entry-meta"> 发布于 <a href="/index.html?time=2020-10-02" title="2020-10-02" rel="bookmark"> <time class="entry-date" datetime="2020-10-02" >{$select_v['date']}</time > </a>。 属于 <a href="/index.html?cate=4" title="查看 Linux中的全部文章" rel="category" >{$select_v['cat']}</a>分类 </footer> </article> </div> {/foreach} <div class="page"> <nav> <ul class="pagination"> <li class="page-item disabled" aria-disabled="true" aria-label="« 上一页"> <span class="page-link" aria-hidden="true">‹</span> </li> <li class="page-item active" aria-current="page"> <span class="page-link">1</span> </li> <li class="page-item"> <a class="page-link" href="/index.html?page=2">2</a> </li> <li class="page-item"> <a class="page-link" href="/index.html?page=2" rel="next" aria-label="下一页 »">›</a> </li> </ul> </nav> </div> </div> <div id="secondary" class="widget-area" role="complementary"> <aside id="search-2" class="widget widget_search"> <form role="search" id="searchform" action="" method="POST"> <div> <label class="screen-reader-text" for="t">搜索:</label> <input placeholder="搜索" type="text" class="no-border" name="keywords" id="t"/> <input type="submit" class="btn btn-default" id="searchsubmit" value="搜索" /> </div> </form> <script type="text/javascript"> $(function (){ $("#searchsubmit").click(function (){ if($("#t").val() != '') { location.href = "/index.html?t="+$("#t").val(); } return false; }); }); </script> </aside> <aside id="recent-posts-2" class="widget widget_recent_entries"> <h3 class="widget-title">热门文章</h3> <ul> {foreach($select as $select_v)} {if $select_v.hot==1} <li> <font style="color:#7a7a7a;">[{$select_v.id}]</font> <a href="/details.html?id=20" title="{$select_v.title}">{$select_v.title}</a> </li> {/if} {/foreach} </ul> </aside> </div> </div> <footer id="colophon" role="contentinfo"> <div class="site-info"> <span>友情链接:</span> <a href="https://www.php.cn" target="_blank">PHP中文网</a> </div> </footer> <footer role="contentinfo" style="margin-top:0;"> <div class="site-info" style="text-align:center;"> <span> <a href="https://beian.miit.gov.cn" target="_blank">苏ICP备2020058653号-1</a> </span> </div> </footer> </div></body></html>
控制器
<?phpnamespace app\controller;use app\BaseController;use think\facade\Db;class Index extends BaseController{ public function index() { $name = input('get.name',''); $search = input('get.t',''); $data['cat'] = Db::name('cat')->where('status',1)->order('sort desc')->select(); if(!empty($name)) { $data['select'] = Db::name('boke')->where('cat',$name)->order('date desc')->select(); } else if(!empty($search)){ $data['select'] = Db::name('boke')->whereLike('title',"%$search%")->order('date desc')->select(); } else { $data['select'] = Db::name('boke')->order('date desc')->select(); } return view('index',$data); }}
效果