您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程

PHPCMSV9二次开发自定义字段模型的方法

冰夏2025-05-29phpcms教程已有人查阅

导读打开phpcms\modules\content\fields目录,复制文件夹downfiles,并改名为textgroups。打开phpcms\modules\content\fields\fields.inc.PHP文件,增加字段类型:

步骤/方法
打开phpcms\modules\content\fields目录,复制文件夹downfiles,并改名为textgroups。打开phpcms\modules\content\fields\fields.inc.PHP文件,增加字段类型:
'textgroups'=>'多文件上传',
打开phpcms\modules\content\fields\textgroups目录(第一步复制的文件夹),修改以下文件:
form.inc.php
function textgroups($field, $value, $fieldinfo) {
extract(string2array($fieldinfo['setting']));
$list_str = '';
if($value) {
$value = string2array(html_entity_decode($value,ENT_QUOTES));
if(is_array($value)) {
foreach($value as $_k=>$_v) {
$list_str .= "<div id='textsgroups{$_k}'> <input type='text' name='{$field}_fx[]' value='{$_v[fx]}' style='width:100px;' class='input-text'> <input type='text' name='{$field}_fj[]' value='{$_v[fj]}' style='width:100px;' class='input-text'> <input type='text' name='{$field}_cx[]' value='{$_v[cx]}' style='width:100px;' class='input-text'> <input type='text' name='{$field}_kd[]' value='{$_v[kd]}' style='width:100px;' class='input-text'> <input type='text' name='{$field}_vip[]' value='{$_v[vip]}' style='width:100px;' class='input-text'> <a href=\"JavaScript:remove_div('textsgroups{$_k}')\">".L('remove_out')."</a></div>";
}
}
}
$string ='<script type=text/javascript>
function add_textsfile(returnid) {
var ids = parseInt(Math.random() * 10000);
var str = "<li id=\'textsgroups"+ids+"\'> <input type=\'text\' name=\'"+returnid+"_fx[]\' value=\'\' style=\'width:100px;\' class=\'input-text\'> <input type=\'text\' name=\'"+returnid+"_fj[]\' value=\'\' style=\'width:100px;\' class=\'input-text\'> <input type=\'text\' name=\'"+returnid+"_cx[]\' value=\'\' style=\'width:100px;\' class=\'input-text\'> <input type=\'text\' name=\'"+returnid+"_kd[]\' value=\'\' style=\'width:100px;\' class=\'input-text\'> <input type=\'text\' name=\'"+returnid+"_vip[]\' value=\'\' style=\'width:100px;\' class=\'input-text\'> <a href=\"javascript:remove_div(\'textsgroups"+ids+"\')\">Remove</a> </li>";
$(\'#\'+returnid).append(str);
}</script>';
$string .= '<input name="info['.$field.']" type="hidden" value="1">
<fieldset class="blue pad-10">
<legend>'.L('mm_fxlist').'</legend><div id="tt">
<input type="text" value="'.L('mm_fx').'" readonly style="width:100px;border:0;" class="input-text">
<input type="text" value="'.L('mm_fj').'" readonly style="width:100px;border:0;" class="input-text">
<input type="text" value="'.L('mm_cx').'" readonly style="width:100px;border:0;" class="input-text">
<input type="text" value="'.L('mm_kd').'" readonly style="width:100px;border:0;" class="input-text">
<input type="text" value="'.L('mm_lyj').'" readonly style="width:100px;border:0;" class="input-text">
</div>';
$string .= $list_str;
$string .= '<ul id="'.$field.'" class="picList"></ul>
</fieldset>
<div class="bk10"></div>
';
$string .= $str."<input type=\"button\" class=\"button\" value=\"".L('mm_addfx')."\" onclick=\"add_textsfile('{$field}')\">";
return $string;
}
修改input.inc.php
function textgroups($field, $value) {
$hotel = $_POST[$field.'_fx'];
$hotel_fj = $_POST[$field.'_fj'];
$hotel_cx = $_POST[$field.'_cx'];
$hotel_kd = $_POST[$field.'_kd'];
$hotel_vip = $_POST[$field.'_vip'];
$array = $temp = array();
if(!empty($hotel)) {
foreach($hotel as $key=>$hote) {
$temp['fx'] = $hote;
$temp['fj'] = $hotel_fj[$key];
$temp['cx'] = $hotel_cx[$key];
$temp['kd'] = $hotel_kd[$key];
$temp['vip'] = $hotel_vip[$key];
$array[$key] = $temp;
}
}
$array = array2string($array);
return $array;
}
修改的output.inc.php
function textgroups($field, $value) {
return string2array($value);
}
更新后台缓存。在模型中新建字段,可以看到文本组,创建后就可以添加。前台调用:
<table>
<tr><th>房型</th><th>房价</th><th>床型</th><th>路游价</th></tr>
{loop $fxinfo $v} <!--$fxinfo为字段名称-->
<tr><td>{$v[fx]}</td><td>¥{$v[fj]}元</td><td>{$v[cx]}</td><td><strong style="color:#f60;font-size:18px;font-family:Tahoma,Helvetica,Arial,sans-serif;">¥{$v[vip]}</strong>元</td></tr>
{/loop}
</table>
注意事项
注意修改几个文件中的函数名称,这个很容易忽略。注意文件内容中引号的闭合和JS代码。

本文标签:

很赞哦! ()

相关源码

  • (PC+WAP)蓝色钢结构机械五金工程建筑基建营销型pbootcms模板下载于PbootCMS开发的钢结构与工程机械专用模板,助力企业构建专业级产品展示平台;模板内置工程案例展示、产品参数对照表等专业模块,预设项目进度、施工方案等建筑行业专属栏目查看源码
  • 帝国cms7.5个人博客资讯文章模板下载本模板简洁个人博客网站设计开发,采用帝国CMS内核构建,只需替换文字图片即可快速搭建专业网站。自适应手机端设计,数据实时同步,操作简单便捷。PHP程序确保安全稳定运行,帮助您以较低成本获取持续业务。查看源码
  • 帝国CMS7.5H5小游戏模板游戏攻略下载网整站源码本模板基于帝国CMS系统开发,为H5小游戏和APP应用资讯类网站设计。模板架构针对小游戏行业特点优化,支持游戏发布、资讯分享、应用推荐等功能,满足各类小游戏门户网站的建设需求。查看源码
  • (自适应响应式)化妆美容口红唇膏化妆品模板pbootcms源码下载基于PbootCMS开发的响应式模板,为化妆品品牌、美容机构打造,通过优雅的视觉呈现提升产品展示效果与品牌调性。采用时尚杂志排版风格,色卡系统规范产品展示。微交互动画增强用户体验,智能推荐算法提升产品关联展示效果。查看源码
  • 帝国CMS中小学生知识点试题练习题考试源码下载基于帝国CMS后台管理系统,支持在线修改联系信息、网站参数等配置,操作流程简洁明了。专注于中小学教育领域,集成知识点总结、试题练习、考试资讯等学习资源,为师生提供全面的在线学习支持与服务。查看源码
  • pbootcms网站模板响应式全屏旅游景区网站源码本模板为风景民宿、旅游景区等企业设计,基于PbootCMS内核开发,具备响应式布局与专业SEO优化功能,助力企业低成本高效获客。以下是核心特点:查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐