[PHPCMS V9二次開發]自訂欄位模型-添加欄位類型

來源:互聯網
上載者:User

標籤:loop   post   size   .net   vip   end   net   php   output   

步驟/方法
  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代碼。

  •  

    • 摘自:http://blog.csdn.net/shunzi110/article/details/8269571

[PHPCMS V9二次開發]自訂欄位模型-添加欄位類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.