thinkphp5项目--个人博客(八)
thinkphp5项目--个人博客(八)
项目地址
fry404006308/personalBlog: personalBlog
https://github.com/fry404006308/personalBlog
一、搜索功能

控制器
<?php
namespace app\index\controller; use app\index\controller\Base;
class Search extends Base
{
public function index()
{
$keywords=input('keywords');
if($keywords){
//按照标题搜索
$map['title']=['like','%'.$keywords.'%'];
$searchres=db('article')->where($map)->order('id desc')->paginate($listRows=3,$simple=false,$config=['query'=>array('keywords'=>$keywords)]);
$this->assign(array(
'searchres'=>$searchres,
'keywords'=>$keywords,
));
}else{
$this->assign(array(
'searchres'=>null,
'keywords'=>'暂无数据',
));
}
return view();
}
}
按照文章标题搜索
//按照标题搜索
$map['title']=['like','%'.$keywords.'%'];
$searchres=db('article')->where($map)->order('id desc')->paginate($listRows=3,$simple=false,$config=['query'=>array('keywords'=>$keywords)]);
视图用的是cate控制器的,把它的复制了一份拿过来用,改了点小位置
二、分页传递参数
thinkphp教程
分页参数
主要的分页参数如下: 参数描述
list_rows 每页数量
page 当前页
path url路径
query url额外参数
fragment url锚点
var_page 分页变量
type 分页类名
项目中实例
//按照标题搜索
$map['title']=['like','%'.$keywords.'%'];
$searchres=db('article')->where($map)->order('id desc')->paginate($listRows=3,$simple=false,$config=['query'=>array('keywords'=>$keywords)]);
视图
{$searchres->render()}
不同分页传来的数据不同,前面部分是变化的
thinkphp5项目--个人博客(八)的更多相关文章
- thinkphp5项目--个人博客(五)
thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(七)
thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(六)
thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(四)
thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(三)
thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(一)
thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- thinkphp5项目--个人博客(二)
thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...
- 2015-2016-2 《Java程序设计》项目小组博客
2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...
- 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)
团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...
随机推荐
- 数据库范式1NF 2NF 3NF BCNF(实例)通俗易懂的讲解
[转] 数据库范式1NF 2NF 3NF BCNF(实例)通俗易懂的讲解 本文对大多数初学数据库原理的同学绝对是个大福利,哈哈,完完整整的看完此篇博文一定能够清晰地理解数据库的四大范式. ...
- ASP.NET-Router配置中MapRoute的参数
App_Start文件夹中的RouteConfig MapRoute(string name,string url); MapRoute(string name,string url,object d ...
- HDU 4303 Contest 1
说实话,挺复杂的一道题. 我采用栈的方式,DFS在搜索完一个节点的所有子结点后,通过排序,加快计算该结点所有可能的路径:子结点与子结点的连通,子结点与父结点的连通,通过父结点与各祖先结点的连通.同时记 ...
- hibernate之4.延迟载入
延迟载入: 仅仅有当使用以实体对象的属性(除主键属性外)时,才会发送查询语句到数据库 get不支持延迟载入 @Test public void getTest(){ Session session=n ...
- Linux就该这么学 20181005(第九章SSH远程对话)
参考链接https://www.linuxprobe.com/ nmtui开启网卡设置 ONBOOT=yes systemctl restart network nmcli connection sh ...
- 让placeholder中的默认文字居中,或者缩进多少像素
直接给input或者textarea的样式加texta-align:center; <input type="" name="" id="&qu ...
- AOJ GRL_1_C: All Pairs Shortest Path (Floyd-Warshall算法求任意两点间的最短路径)(Bellman-Ford算法判断负圈)
题目链接:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C All Pairs Shortest Path Input ...
- ASP.NET使用MergeInto做数据同步,同步SQLSERVER不同数据库的相同表结构的数据
public string SynchronousData() { ReturnJson Rejson = new ReturnJson(); //将WebConfig中的数据库连接name中的值写进 ...
- ASM磁盘组中的AU与条带
一.AU与条带(AU和条带就是一个分配单位,数据会被以一定单位分割,存储在多个磁盘中.分割单位的大小由AU.条带来决定. ASM有两种条带: 1.不可调粗粒度: 相当于ASM没有条带,或者说AU就是条 ...
- split方法切割数组
指定的字符串按"o"截取 当一个base64需要剪去前面的部分的时候 var params={ "imgJustBase64":this.zheng.split ...