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. mysql5.7官网直译SQL语句优化--select语句优化

    8.2 sql语句优化 大致内容如下: 8.2.1:SELECT语句的优化 8.2.2:优化子查询,派生表和试图引用 8.2.3:优化INFORMATION_SCHEMA查询 8.2.4:优化数据改变 ...

  2. Collection、List、Set、Map之间的关系

    初学java,单个的接触有点迷糊,所以总结下他们的关系 一.关系 Collection --List:以特定顺序存储 --ArrayList.LinkList.Vector --Set:不能包含重复的 ...

  3. 小胖说事30------iOS 强制转成横屏的方式

    一直遇到这个问题,今天最终找到了解决方法. 在我们的项目中常常遇到横竖屏切换,而又有某个特定的界面必须是特定的显示方式(横屏或竖屏).这就须要例如以下的处理了. 强制转成横屏: if ([[UIDev ...

  4. start_kernel——boot_cpu_init及PER_CPU

    init/main.c /* * Activate the first processor. */ static void __init boot_cpu_init(void) { int cpu = ...

  5. 在fragment中显示对话框出现异常

    异常类型为:android.view.WindowManager$BadTokenException: Unable to add window 我在fragment中public View onCr ...

  6. 【源代码】将一个整数的每位数分解并按逆序放入一个数组中(用递归算法)(C语言实现)

    帮朋友做的,好像是一个面试题.假设不过考察递归的话.应该是够了,程序的健壮性和通用性都非常一般的说-- #include <stdio.h> #include <stdlib.h&g ...

  7. elasticsearch的javaAPI之index

    Index API 原文:http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html ...

  8. [JZOJ 5906] [NOIP2018模拟10.15] 传送门 解题报告(树形DP)

    题目链接: https://jzoj.net/senior/#contest/show/2528/2 题目: 8102年,Normalgod在GLaDOS的帮助下,研制出了传送枪.但GLaDOS想把传 ...

  9. 【参考】IBM sun.io.MalformedInputException and text encoding conversions transforms numerals to their word equivalents - United States

    Problem(Abstract) When converting contents from a file or string using WebSphere Application Server, ...

  10. jquery根据接口返回的值来设置asp:CheckBoxList的选中值

    接口返回一个json的值,然后通过jquery来选中asp:CheckBoxList相应选中的值 <asp:CheckBoxList runat="server" Repea ...