加入字段为types 选项为 线路和新闻的字段
\application\admin\controller\cms\Archives.php
//576行
$publishfields = $setting['publishfields'] ?? [];
//只在模型ID4显示
if($model_id==4){
$publishfields[]="types";
}
$titlelist = $setting['titlelist'] ?? [];
$this->view->assign('channel', $channel);
//108
$this->view->assign("typesList", $this->model->getTypesList());
\application\admin\lang\zh-cn\cms\Archives.php
'Types' => "数据类型",
"TYpes xl" => "线路",
"TYpes xw" => "新闻"
\application\admin\model\cms\Archives.php
public function getTypesList()
{
return ['xl' => __('Types xl'), 'xw' => __('Types xw')];
}
\application\admin\view\cms\archives
edit.html
<div class="form-group" data-field="types">
<label class="control-label col-xs-12 col-sm-2">{:__('Types')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="typesList" item="vo"}
<label for="row[types]-{$key|htmlentities}"><input id="row[types]-{$key|htmlentities}" name="row[types]" type="radio" value="{$key|htmlentities}" {in name="key" value="$row.types"}checked{/in} /> {$vo|htmlentities}</label>
{/foreach}
</div>
</div>
</div>
add.html
<div class="form-group" data-field="types">
<label class="control-label col-xs-12 col-sm-2">{:__('Types')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="radio">
{foreach name="typesList" item="vo"}
<label for="row[types]-{$key|htmlentities}"><input id="row[types]-{$key|htmlentities}" name="row[types]" type="radio" value="{$key|htmlentities}" {in name="key" value="xl"}checked{/in} /> {$vo|htmlentities}</label>
{/foreach}
</div>
</div>
</div>
\public\assets\js\backend\cms\Archives.js
{field: 'types', title: __('Types'), searchList: {"xl": __('Types xl'), "xw": __('Types xw')}, formatter: Table.api.formatter.status},
//前台列表区分数据
\addons\cms\controller\Channel.php
//
if(input("t")=="xw"){
$typeswhere["types"]="xw";
}else{
$typeswhere["types"]="xl";
}
//分页模式
$simple = !($config['loadmode'] == 'paging' && $config['pagemode'] == 'full');
//缓存列表总数
if (!$simple && ($config['cachelistcount'] ?? false)) {
$simple = Archives::with(['channel', 'user'])->alias('a')
->where('a.status', 'normal')
->whereNull('a.deletetime')
->where($filterWhere)
->bind($filterBind)
->where($filterPagelist)
->where($filterChannel)
->where($typeswhere)
->where('model_id', $channel->model_id)
->join($model['table'] . ' n', 'a.id=n.id', 'LEFT')
->cache("cms-channel-list-" . $channel['id'] . '-' . md5(serialize($filter)), 3600, "cms") //总数缓存1小时
->count();
}
//加载列表数据
$pageList = Archives::with(['channel', 'user'])->alias('a')
->where('a.status', 'normal')
->whereNull('a.deletetime')
->where($filterWhere)
->bind($filterBind)
->where($filterPagelist)
->where($filterChannel)
->where($typeswhere)
->where('model_id', $channel->model_id)
->join($model['table'] . ' n', 'a.id=n.id', 'LEFT')
->field('a.*')
->field('id,content', true, config('database.prefix') . $model['table'], 'n')
->order($orderby, $orderway)
->paginate($pagesize, $simple);
发表评论 取消回复