phpcms v9,我们在做类似于酒店房型等类型的时候,需要用到文本组字段模型,但phpcms并未提供该模型。如下图所示效果:

展示效果如下:

步骤/方法

  1. 打开phpcms\modules\content\fields目录,复制文件夹downfiles,并改名为textgroups。

  2. 打开phpcms\modules\content\fields\fields.inc.php文件,增加字段类型:

    'textgroups'=>'多文件上传',

  3. 打开phpcms\modules\content\fields\textgroups目录(第一步复制的文件夹),修改以下文件:

  4. 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;
    }

  5. 修改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;
    }

  6. 修改的output.inc.php

    function textgroups($field, $value) {

    return string2array($value);

    }

  7. 更新后台缓存。在模型中新建字段,可以看到文本组,创建后就可以添加。

  8. 前台调用:<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代码。

PHPCMS V9二次开发]自定义字段模型-文本组的更多相关文章

  1. [PHPCMS V9二次开发]自定义字段模型-添加字段类型

    步骤/方法 打开phpcms\modules\content\fields目录,复制文件夹downfiles,并改名为textgroups. 打开phpcms\modules\content\fiel ...

  2. phpcms v9二次开发之模型类的应用(1)

    在<phpcms二次开发之模型类model.class.php>中讲到了模型类的建立方法,接下来我讲一下模型类的应用.      前段时间我基于phpcms v9开发了一个足球网.足球网是 ...

  3. phpcms v9二次开发之模型类的应用(2)

    二.模型操作方法select()--查询语句         //查询级别管理列表信息    public function levellists() { $lelists = $this->l ...

  4. PHPCMS V9二次开发便捷自定义后台入口文件夹

    phpcms v9二次开发便捷自定义后台入口文件夹 最新发布的phpcms v9由于采用了mvc的设计模式,所以它的后台访问地址是固定的,虽然可以通过修改路由配置文件来实现修改,但每次都修改路由配置文 ...

  5. phpcms v9二次开发之数据模型类

    系统模型类:model.class.php数据模型类的位置:/phpcms/libs/classes phpcms v9二次开发中,我们要经常需要对模块的数据表进行查询.添加.修改和删除数据等操作,所 ...

  6. PHPCMS V9 二次开发常用代码集

    0:调用最新文章,带所在版块 {pc:get sql="SELECT a.title, a.catid, b.catid, b.catname, a.url as turl ,b.url a ...

  7. phpcms v9二次开发笔记

    phpcms是基于MVC结构的. 安装: 下载phpcms_v9.5.9_UTF8.zip:新建目录phpcms,将压缩包里install_package目录下所有文件复制到phpcms目录.浏览器输 ...

  8. V9 二次开发技术篇之 模型数据库

    应V9粉丝的建议,本人今天讲一下 MVC中的M 数据库模型 首先 在 phpcms\model  建一个模型文件test_model.class.php <?phpdefined('IN_PHP ...

  9. phpcms V9 二次开发------(获取点击数详解)

    关于phpcms V9的点击数的使用应该有不少数是直接调用网上搜索到的代码,但是对于一些想要深入研究开发的人来说,看到网上的代码后更是不解,本人这几天看了看,了解了一些东西,在这里写出来分享一下,首先 ...

随机推荐

  1. lr 自带的例子,如何进行关联,通过代码的函数进行实现

    本篇主要介绍如何来进行把参数进行关联,首先对web tours进行设定 如下图 点击“administration”j进入跳转页面,如下图所示 勾选第三项,下拉下方,点击“update”按钮, 关闭浏 ...

  2. gcc编译命令

    g++ demo.cpp -o demo.exe

  3. js打开新的链接2

    window.open打开新的连接时可能会被浏览器拦截掉. 所以采用动态创建a标签的形式. var a = document.createElement('a');  a.href = myUrl;  ...

  4. Java程序打包

    包名为 com.longneo.data,主程序入口为:com.longneo.data.AppMain 1.到工程目录下 /bin 执行 jar -cvf Demo.jar com 执行完之后会生成 ...

  5. Hu矩SVM训练及检测-----OpenCV

    关键词:Hu矩,SVM,OpenCV 在图像中进行目标物识别,涉及到特定区域内是否存在目标物,SVM可在样本量较少情况下对正负样本(图片中前景背景)做出良好区分,图片基本特征包括诸如HOG.LBP.H ...

  6. java垃圾回收算法

    1.标记-清除 2.标记-复制 3.标记-整理 4.分代混合算法

  7. JStorm 是一个分布式实时计算引擎

    alibaba/jstorm JStorm 是一个分布式实时计算引擎. JStorm 是一个类似Hadoop MapReduce的系统, 用户按照指定的接口实现一个任务,然后将这个任务递交给JStor ...

  8. Oracle&#39;s Business Intelligence Applications Configuration Manager 基本概念

    Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installatio ...

  9. C#视频总结

    C#视频利用了四天看完了,由于有VB的基础.所以看起来并没有感觉太吃力.在主要的数据类型.运算之间没有多大的差别. 在循环控制语句上也就是大同小异.在类.继承和多态方面可能有一些陌生,可是经过了前期的 ...

  10. SDWebImage 图片缓存机制

    SDWebImage与iOS系统自带的缓存相比,优势是什么? 从iOS5开始,iOS NSURLCache对于原生得HTTP Response做内存和磁盘缓存.每一次缓存命中(缓存命中就是说内存或者磁 ...