今天群里有人咨詢后臺要設置自定義字段的搜索(按id、按標題、按副標題、按作者等等),其實很簡單.
在apps/admin/model/content/ContentModel.php中
//查找指定分類及子類文章及//在全部欄目查找文章中將
->like('a.title',?$keyword)
改為
->like('a.title,a.要新增的字段',$keyword)
如果需要查找自定義字段,需要在$fields=array(里將自定義字段添加好,然后在like里添加上即可。教程如下:
開始修改如下
首頁打開 apps–>admin–>model–>content 中的 ContentModel.php 文件。
修改函數 public function findContent($mcode, $scode, $keyword) 中相關代碼:
在大概 115 行處加入 ‘content_ext.*’ 代碼;
在大概 134 行處加入以下代碼:
array(
????'ay_content_ext?content_ext',
????'a.id=content_ext.contentid',
????'LEFT'
)
在大概 147 行處 把原來的代碼 ->like(‘a.title’, $keyword) 修改成你要搜索的自定義字段 ->like(‘content_ext.ext_zsm’, $keyword)
public function findContentAll($mcode, $keyword) 這個函數中的修改方法如上。