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. c/c++关于内存分配的知识(非常详细的比较,且VirtualAlloc分配内直接在进程的地址空间中保留一快内存)

    一个由c/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. 2.堆区(heap) — 一 ...

  2. 新的疑问(未解决):VC项目的配置,不是都能在Project -- Properties里设置解决的

    现象:死活解决不了引入外部库的LPCWSTR参数传递问题.而用VS新建的项目,就没有这个问题. 我怀疑是当初.pro文件产生VC项目文件时候,做了一些设置,但是内容太长了,又很复杂,所以没法核对. 用 ...

  3. Android的5个进程等级(转)

    1.foreground process     正处于activity resume状态     正处于bound服务交互的状态     正处于服务在前台运行的状态(StartForeGround( ...

  4. Visual Studio Code 与 Github 集成

    使用Visual Studio Code进行Nodejs开发充满了便利,为了更好的进行开发工作,有必要使用Github进行代码管理. Visual Studio Code已经集成了GIT组件: htt ...

  5. SDL_PingGe 1.2

    加入了像素填充函数,必须要在一个指定颜色的边界范围内,边界必须没有缺口. 加入了鼠标类 /* typedef void (*FUNCTION)(void); HMODULE HDll; HDll = ...

  6. 关于jsp中超链接的相对路径

    前提:新建了一个名为MyProject的web工程.在WebContent目录下新建一个jsp目录,在jsp目录中新建一个index.jsp文件. 实验:在index.jsp里写了4个链接,如下: & ...

  7. Robot Framework安装配置 Linux

    Simple introduction Robot Framework is a generic test automation framework for acceptance testing an ...

  8. 使用PHPExcel导出数据

    最近要求做增加客流数据等导出为Excel的功能,phpExcel包功能强大,根据实际需求,我只学习了简单的功能. 安装PHPExcel 在composer.json中添加: "require ...

  9. mongodb的write concern

    mongodb有一个write concern的设置,作用是保障write operation的可靠性.一般是在client driver里设置的,和db.getLastError()方法关系很大 一 ...

  10. [RxJS] Creation operators: empty, never, throw

    This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...