适用于继承table类的控制器文件,需要精通php的开发者

功能介绍:在列表搜索时,默认的搜索方式是模糊匹配,比如我需要改成以空格为分隔进行多词语搜索

{xunruicms_img_title}

默认情况下会将【词语一 词语二】当成一个词语进行数据库查询搜索。

现在,我们需要将他按空格分成两个词语分别进行模糊查询,当包含其中某一个词语时就表示搜索成功。


用法说明:

1、打开内容模块列表控制器

/dayrui/App/Demo/Controllers/Admin/Home.php

2、为主题字段加上自定义搜索函数

<?php namespace Phpcmf\Controllers\Admin;

class Home extends \Phpcmf\Admin\Module
{

   public function index() {
        $this->init['field']['title']['myfunc'] = 'mytitlewhere'; // 这是我增加的
      $this->_Admin_List();
   }


3、打开文件config/costom.php中定义这个函数:mytitlewhere

function mytitlewhere($param) {

    $rt = [];
    $arr = explode(' ', $param['keyword']);
    if ($arr) {
        foreach ($arr as $t) {
            $rt[] = $param['field'].' LIKE "%'.$t.'%"';
        }
    }

    return $rt ? implode(' OR ', $rt) : '';
}

这个函是将字符拆分成多个词语进行OR匹配



文档最后更新时间:2023-10-24 07:12:01
我来修改此文档(1) 不会操作怎么办?