迅睿CMS框架是一款PHP8高性能·簡單易用的CMS開源開發框架,基于MIT開源許可協議發布,免費且不限制商業使用,是免費開源的產品,以萬端互聯為設計理念,支持的微信公眾號、小程序、APP客戶端、移動端網站、PC網站等多終端式管理系統。
聯系官方銷售客服
1835022288
028-61286886
在不影響升級的情況下,內容關聯實現poscms3中的內容關聯可以拖動排序,同時可以重復關聯同一條內容。比如,可以關聯3條id為17的內容。
dayrui/My/Field/Related.php
<?php namespace My\Field; // 這里要改成My前綴 /** * http://www.zbshanke.com * 本文件是框架系統文件,二次開發時不可以修改本文件,可以通過繼承類方法來重寫此文件 **/ class Related extends \Phpcmf\Field\Related { /** * 字段表單輸入 * * @param string $cname 字段別名 * @param string $name 字段名稱 * @param array $cfg 字段配置 * @param string $value 值 * @return string */ public function input($field, $value = '') { // 字段禁止修改時就返回顯示字符串 if ($this->_not_edit($field, $value)) { return $this->show($field, $value); } // 字段存儲名稱 $name = $field['fieldname']; // 字段提示信息 $tips = isset($field['setting']['validate']['tips']) && $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$name.'_tips">'.$field['setting']['validate']['tips'].'</span>' : ''; // 禁止修改 $area = \Phpcmf\Service::C()->_is_mobile() ? '["95%", "90%"]' : '["50%", "45%"]'; // 模塊名稱 $module = isset($field['setting']['option']['module']) ? $field['setting']['option']['module'] : ''; // $tpl = '<tr id="dr_items_'.$name.'_{id}"><td>{id}</td><td>{value}<input type="hidden" name="data['.$name.'][]" value="{id}"></td><td width="45"><a class="btn btn-xs red" href="javascript:;" onclick="$(\\\'#dr_items_'.$name.'_{id}\\\').remove()"><i class="fa fa-trash"></i></a></td></tr>'; // $url = '/index.php?s=api&c=api&m=related&site='.SITE_ID.'&module='.$module.'&limit='.intval($field['setting']['option']['limit']); // 字段顯示名稱 $text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').$field['name']; $str = ''; $str.= ' <table class="table table-striped table-bordered fc-sku-table table-hover"> <thead> <tr> <th width="90" style="border-left-width: 1px!important;">Id </th> <th>'.dr_lang('主題').' </th> <th width="50"> </th> </tr> </thead> <tbody id="related_'.$name.'-sort-items">'; $value = @trim($value, ','); if ($value && is_string($value)) { $ids = explode(',', $value); foreach ($ids as $t) { $id = intval($t); $t = \Phpcmf\Service::M()->table(SITE_ID.'_'.$module)->get($id); $value = '<a href="'.$t['url'].'" target="_blank">'.$t['title'].'</a>'; $str.= str_replace(array('{id}', '{value}', '\\'), array($id, $value, ''), $tpl); } } $str.= '</tbody>'; $str.= '</table>'; $str.= '<p>'; $str.= '<button type="button" class="btn blue btn-sm" onClick="dr_add_related_'.$name.'()"> <i class="fa fa-plus"></i> '.dr_lang('關聯內容').'</button>'; $str.= '</p>'; $str.= $tips; $str.= ' <script type="text/javascript"> $("#related_'.$name.'-sort-items").sortable(); function dr_add_related_'.$name.'() { layer.open({ type: 2, title: \'<i class="fa fa-cog"></i> '.dr_lang('關聯內容').'\', fix:true, shadeClose: true, shade: 0, area: '.$area.', btn: ["'.dr_lang('關聯').'"], success: function (json) { if (json.code == 0) { layer.close(); dr_tips(json.code, json.msg); } }, yes: function(index, layero){ var body = layer.getChildFrame(\'body\', index); // 延遲加載 var loading = layer.load(2, { time: 10000 }); $.ajax({type: "POST",dataType:"json", url: "'.$url.'&is_ajax=1", data: $(body).find(\'#myform\').serialize(), success: function(json) { layer.close(loading); if (json.code == 1) { layer.close(index); var temp = \''.$tpl.'\'; var html = ""; for(var i in json.data.result){ var tpl = temp; var v = json.data.result[i]; tpl = tpl.replace(/\{id\}/g, v.id); tpl = tpl.replace(/\{value\}/g, v.value); html+= tpl; } $(\'#related_'.$name.'-sort-items\').append(html); dr_tips(1, json.msg); } else { dr_tips(0, json.msg); } return false; } }); return false; }, content: "'.$url.'&is_ajax=1" }); } </script>'; return $this->input_format($name, $text, $str); } }
前段怎么調用?
只能出一條呢~~
回復@靠懸賞(設置懸賞)賺錢買授權
看在賞金的份上
show.html
{php $ids=explode(",", $字段名稱);}
{loop $ids $iii} <hr> {content id=$iii module=news} 標題:{$t.title} 內容:{$t.content} 自定義更新時間:{dr_date($t._updatetime, 'Y-m-d')} {/content} <hr> {/loop}
dayrui/My/Field/Related.php
前段怎么調用?
只能出一條呢~~
回復@靠懸賞(設置懸賞)賺錢買授權
看在賞金的份上
show.html
{php $ids=explode(",", $字段名稱);}