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项目--个人博客(八)的更多相关文章

  1. thinkphp5项目--个人博客(五)

    thinkphp5项目--个人博客(五) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  2. thinkphp5项目--个人博客(七)

    thinkphp5项目--个人博客(七) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  3. thinkphp5项目--个人博客(六)

    thinkphp5项目--个人博客(六) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  4. thinkphp5项目--个人博客(四)

    thinkphp5项目--个人博客(四) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  5. thinkphp5项目--个人博客(三)

    thinkphp5项目--个人博客(三) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  6. thinkphp5项目--个人博客(一)

    thinkphp5项目--个人博客(一) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. 2015-2016-2 《Java程序设计》项目小组博客

    2015-2016-2 <Java程序设计>项目小组博客 1451 完+美 java项目 守望先疯 JavaGroup 07_10_20_22 FromBottomToTop L.G.Su ...

  9. 团队项目系列博客 —— 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号)

    团队项目系列博客 -- 在路上(之wampserver 修改根目录以及配置多站点以及修改端口号) 标签(空格分隔): wampserver php 参考:参考文献1.慕课网.知乎.github 一.w ...

随机推荐

  1. Maven多模块项目搭建

    最近一直在思考如何能够更好的重用代码.减少重复劳动,之前有一篇文章通过导入JAR包的形式,可以重用部分形如util类的方法,但是这样的话,管理起来jar包,特别是协同工作,多项目情况下,管理JAR会出 ...

  2. 菜鸟学Struts——I18N对国际化的支持

    大家肯定都喜欢玩游戏吧. 对于是一个游戏迷的话,肯定玩过不少很棒的经典单机游戏.比方说,国产的<古墓丽影>.<刺客信条>.<鬼泣>国产的仙剑.古剑等.在众多游戏系列 ...

  3. sap abap 对字符串的操作

    替换字段内容 REPLACE [FIRST /ALL OCCURRENCES OF]<STR1>INTO <STR> WITH <STR2>   DATA STR ...

  4. HDU 5358 First One(枚举)

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  5. ubuntu中taglist和ctags安装,简单明了

    1.使用命令安装ctags: sudo apt-get install ctags 2.安装taglist 下载: http://vim.sourceforge.net/scripts/downloa ...

  6. html表格设计

    html部分,biaoge.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  7. thinkphp项目上传到github,为什么缺少很多文件

    thinkphp项目上传到github,为什么缺少很多文件 问题: 把tp5项目push到码云(类似github)上,为什么没有thinkphp这个核心库? 然后我看了下码云和github上,官方的t ...

  8. ElasticSearch Shard——本质上是做分布式扩展,副本对于集群的稳定性有很强的影响

    什么是一个Shard? Shard就是一个Lucene Index,参照文章(深入理解Shard和Lucene Index). Index需要多少个Shard? 回答这个问题,我们需要先谈谈节点,一个 ...

  9. poj--3250--Bad Hair Day(模拟)

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit ...

  10. CentOS Linux 加硬盘,分区和设置自动挂载

    sda 表示第1块SCSI硬盘hda 表示第1块IDE硬盘(即连接在第1个IDE接口的Master口上)scd0 表示第1个USB光驱当添加了新硬盘后,在/dev目录下会有相应的设备文件产生.ccis ...