TaoLer/app/index/controller/Search.php

23 lines
569 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\index\controller;
use app\common\model\Article;
class Search
{
public function getSearch(string $keywords)
{
//全局查询条件
$map = []; //所有的查询条件封装到数组中
//条件1
$map[] = ['status','=',1]; //这里等号不能省略
if(!empty($keywords)){
//条件2
$map[] = ['title','like','%'.$keywords.'%'];
$res = Article::where($map)->withCount('comments')->order('create_time','desc')->paginate(10);
return $res;
}
}
}