配置项DB_LIKE_FIELDS无效 无法使用

浏览:631 发布日期:2016/06/02 分类:求助交流
ThinkPHP3.2.3版本
手册上写的配置项
DB_LIKE_FIELDS 设置后无效
配置文件中这么设置

'DB_LIKE_FIELDS'=>'username',

复制代码
按照手册上的,才进行where条件查询时 会对username字段进行模糊查询
然而并没有起到这样的效果 打印查询语句 依旧是进行的精确搜索
查看 Driver.class.php 源码里的构造函数

public function __construct($config=''){
if(!empty($config)) {
var_dump($config); // 此配置数组根本没有 db_like_fields 这个键
$this->config = array_merge($this->config,$config);
if(is_array($this->config['params'])){
$this->options = $this->config['params'] + $this->options;
}
}
}

复制代码
再在parseWhereItem方法里找

$likeFields = $this->config['db_like_fields'];
// var_dump($likeFields); // $likeFields 为空字符串
if($likeFields && preg_match('/^(`'.$likeFields.'`)$/i',$key)) {
$whereStr .= $key.' LIKE '.$this->parseValue('%'.$val.'%');
}else {
// $likeFields 为空 所以直接走这个分支 不进行模糊拼接
$whereStr .= $key.' = '.$this->parseValue($val);
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>