zoukankan      html  css  js  c++  java
  • thinkphp5项目--个人博客(八)

    thinkphp5项目--个人博客(八)

    项目地址

    fry404006308/personalBlog: personalBlog
    https://github.com/fry404006308/personalBlog

    一、搜索功能

    控制器

     1 <?php
     2 namespace appindexcontroller;
     3 
     4 use appindexcontrollerBase;
     5 class Search extends Base
     6 {
     7     public function index()
     8     {
     9         $keywords=input('keywords');
    10         if($keywords){
    11             //按照标题搜索
    12             $map['title']=['like','%'.$keywords.'%'];
    13             $searchres=db('article')->where($map)->order('id desc')->paginate($listRows=3,$simple=false,$config=['query'=>array('keywords'=>$keywords)]);
    14             $this->assign(array(
    15                 'searchres'=>$searchres,
    16                 'keywords'=>$keywords,
    17                 ));
    18         }else{
    19             $this->assign(array(
    20                 'searchres'=>null,
    21                 'keywords'=>'暂无数据',
    22                 ));
    23         }
    24         return view();
    25     }
    26 }

    按照文章标题搜索

    1             //按照标题搜索
    2             $map['title']=['like','%'.$keywords.'%'];
    3             $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 分页类名

    项目中实例

    1             //按照标题搜索
    2             $map['title']=['like','%'.$keywords.'%'];
    3             $searchres=db('article')->where($map)->order('id desc')->paginate($listRows=3,$simple=false,$config=['query'=>array('keywords'=>$keywords)]);

    视图

    {$searchres->render()}

    不同分页传来的数据不同,前面部分是变化的

  • 相关阅读:
    light oj 1105 规律
    light oj 1071 dp(吃金币升级版)
    light oj 1084 线性dp
    light oj 1079 01背包
    light oj 1068 数位dp
    light oj 1219 树上贪心
    light oj 1057 状压dp TSP
    light oj 1037 状压dp
    矩阵快速幂3 k*n铺方格
    矩阵快速幂2 3*n铺方格
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/8817691.html
Copyright © 2011-2022 走看看