需要修改的文件statics\js\content_addtop.js
需要修改的文件phpcms\modules\content\content.php
需要修改的文件phpcms\modules\content\templates\relationlist.tpl.php
依次点击内容->模型管理->添加模型,模型名称和模型表键名按自己需要填写,其它不用修改。
找到刚才新增的模型,打开字段管理,添加自定义字段,字段类型选择万能字段,字段名可以自己取,接着修改系统默认的relation字段表单代码如下:
打开网站根目录文件statics\js\content_addtop.js,修改remove_relation函数:function remove_relation(sid,id,modelname) { var relation_ids = $('#'+modelname).val(); if(relation_ids !='' ) { $('#'+sid).remove(); var r_arr = relation_ids.split('|'); var newrelation_ids = ''; $.each(r_arr, function(i, n){ if(n!=id) { if(i==0) { newrelation_ids = n; } else { newrelation_ids = newrelation_ids+'|'+n; } } }); $('#'+modelname).val(newrelation_ids); }}
接着修改show_relation函数:function show_relation(modelid,id,fieldname) {$.getJSON('?m=content&c=content&a=public_getjson_ids&modelid='+modelid+'&id='+id, function(json){ var newrelation_ids = ''; if(json==null) { alert('没有添加相关文章'); return false; } $.each(json, function(i, n){ newrelation_ids += '
新增show_myrelation函数function show_myrelation(modelid,modelid2,id,fieldname) {$.getJSON('?m=content&c=content&a=public_getjson_ids2&modelid='+modelid+'&modelid2='+modelid2+'&id='+id+'&fieldname='+fieldname, function(json){ var newrelation_ids = ''; if(json==null) { alert('没有添加相关文章'); return false; } $.each(json, function(i, n){ newrelation_ids += '
打开phpcms\modules\content\content.php文件,修改:public_relationlist函数,在$infos = $this->db->listinfo($where,'',$page,12);这句上面增加一句$modelname=$_GET['modelname'];
新增函数public_getjson_ids2:public function public_getjson_ids2() { $modelid = intval($_GET['modelid']); $modelid2 = intval($_GET['modelid2']); $fieldname = $_GET['fieldname']; $id = intval($_GET['id']); $this->db->set_model($modelid); $tablename = $this->db->table_name; $this->db->table_name = $tablename.'_data'; $r = $this->db->get_one(array('id'=>$id),$fieldname); if($r['{$fieldname}']) { $myrelation = str_replace('|', ',', $r['{$fieldname}']); $myrelation = trim($myrelation,','); $where = 'id IN($myrelation)'; $infos = array(); $this->db->set_model($modelid2); $this->model = getcache('model', 'commons'); $this->db->table_name = $this->db->db_tablepre.$this->model[$modelid2]['tablename']; //$this->db->table_name = $tablename; $datas = $this->db->select($where,'id,title'); foreach($datas as $_v) { $_v['sid'] = 'v'.$_v['id']; if(strtolower(CHARSET)=='gbk') $_v['title'] = iconv('gbk', 'utf-8', $_v['title']); $infos[] = $_v; } echo json_encode($infos); } }
打开phpcms\modules\content\templates\relationlist.tpl.php文件,修改:
还有下面的js代码:
好了,大功告成!保存好后,新增文章选择刚才的模型,试试吧!
源码更改后更新会覆盖的,要注意备份