PbootCMS管理后台增加自定义字段显示以及搜索,可显示和搜索其他自定义字段

2025年12月29日15:04:32 发表评论
微信搜一搜 ts小陈

修改方法

需要修改的文件(加粗橘色为新增加的内容)

apps/admin/model/content/ContentModel.php

apps/admin/view/default/content/content.html

一、后台文章管理增加自定义字段的显示

首先在后台全局配置中增加模型字段并记录下字段名称如当行文本ext_chapinid(其他同理)

1、在ContentModel.php文件中做出如下更改

增加你添加的自定义字段,并增加数据库查询方法,最终代码如下:

  1. public function getList($mcode, $where = array())
  2.     {
  3.         $field = array(
  4.             'a.id',
  5.             'b.name as sortname',
  6.             'a.scode',
  7.             'c.name as subsortname',
  8.             'a.subscode',
  9.             'a.title',
  10.             'a.subtitle',
  11.             'a.date',
  12.             'a.sorting',
  13.             'a.status',
  14.             'a.istop',
  15.             'a.isrecommend',
  16.             'a.isheadline',
  17.             'a.visits',
  18.             'a.ico',
  19.             'a.pics',
  20.             'a.filename',
  21.             'a.outlink',
  22.             'd.urlname',
  23.             'b.filename as sortfilename',  // 注意这里添加英文逗号(新增加)
  24.             'e.ext_chapinid'  // 这里是你添加的自定义字段(新增加)
  25.         );
  26.         $join = array(
  27.             array(
  28.                 'ay_content_sort b',
  29.                 'a.scode=b.scode',
  30.                 'LEFT'
  31.             ),
  32.             array(
  33.                 'ay_content_sort c',
  34.                 'a.subscode=c.scode',
  35.                 'LEFT'
  36.             ),
  37.             array(
  38.                 'ay_model d',
  39.                 'b.mcode=d.mcode',
  40.                 'LEFT'
  41.             ),  // 注意这里添加英文逗号(新增加)
  42.            array('ay_content_ext e', 'a.id = e.contentid', 'LEFT')  //这里增加自定义字段的表(新增加)  
  43.         );
  44.         return parent::table('ay_content a')->field($field)
  45.             ->where("b.mcode='$mcode'")
  46.             ->where('d.type=2 OR d.type is null ')
  47.             ->where("a.acode='" . session('acode') . "'")
  48.             ->where($where)
  49.             ->join($join)
  50.             ->order('a.sorting ASC,a.id DESC')
  51.             ->page()
  52.             ->select();
  53.     }

2、在content.html对应位置添加下边代码即可

  1. <td>[value->ext_chapinid]</td>

PbootCMS管理后台增加自定义字段显示以及搜索,可显示和搜索其他自定义字段

 

二、后台文章管理增加自定义字段的搜索

1、在ContentModel.php文件中做出如下更改

在下边两个函数中增加,增加的内容是一样的,最终如下:

public function findContent($mcode, $scode, $keyword)// 查找指定分类及子类文章

public function findContentAll($mcode, $keyword)/ 在全部栏目查找文章

  1. // 查找指定分类及子类文章
  2. public function findContent($mcode, $scode, $keyword)
  3.     {
  4.         $fields = array(
  5.             'a.id',
  6.             'b.name as sortname',
  7.             'a.scode',
  8.             'c.name as subsortname',
  9.             'a.subscode',
  10.             'a.title',
  11.             'a.subtitle',
  12.             'a.date',
  13.             'a.sorting',
  14.             'a.status',
  15.             'a.istop',
  16.             'a.isrecommend',
  17.             'a.isheadline',
  18.             'a.visits',
  19.             'a.ico',
  20.             'a.pics',
  21.             'a.filename',
  22.             'a.outlink',
  23.             'd.urlname',
  24.             'b.filename as sortfilename',  // 注意这里添加英文逗号(新增加)
  25.             'content_ext.ext_chapinid'//这里增加要查询得自定义字段  
  26.         );
  27.         $join = array(
  28.             array(
  29.                 'ay_content_sort b',
  30.                 'a.scode=b.scode',
  31.                 'LEFT'
  32.             ),
  33.             array(
  34.                 'ay_content_sort c',
  35.                 'a.subscode=c.scode',
  36.                 'LEFT'
  37.             ),
  38.             array(
  39.                 'ay_model d',
  40.                 'b.mcode=d.mcode',
  41.                 'LEFT'
  42.             ),  // 注意这里添加英文逗号(新增加)
  43.             array('ay_content_ext content_ext',  
  44.             'a.id=content_ext.contentid', 'LEFT') //这里增加自定义字段的表(新增加)  
  45.         );
  46.         $this->scodes = array(); // 先清空
  47.         $scodes = $this->getSubScodes($scode);
  48.         return parent::table('ay_content a')->field($fields)
  49.             ->where("b.mcode='$mcode'")
  50.             ->where('d.type=2 OR d.type is null ')
  51.             ->where("a.acode='" . session('acode') . "'")
  52.             ->in('a.scode', $scodes)
  53.              ->like('a.title,content_ext.ext_chapinid', $keyword)//这里加入查询的自定义字段  
  54.             ->join($join)
  55.             ->order('a.sorting ASC,a.id DESC')
  56.             ->page()
  57.             ->select();
  58.     }

上边这是 查找指定分类及子类文章 的代码,下边的 在全部栏目查找文章 的代码添加内容和上边的一致即可,然后在后台就可以搜索自定义字段了。

PbootCMS管理后台增加自定义字段显示以及搜索,可显示和搜索其他自定义字段
 

ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

😀

已登录用户不需要填写以下内容