PHPCMS移植到PHP7MySQL8_phpcms 移植【添加相关文章】功能

添加相关文章功能相当有用,移植一个过来基本上可以实现比较复杂的页面内包含分类功能,做二次开发时可以省下不少力气。

用例:如果一个产品,属于一个厂家,而这个厂家是动态添加的,既不是一个分类,而是一个厂家的模型,这二者关联的时候使用这个添加相关的功能可以轻易实现。

学会使用phpcms中的类别管理和推荐位管理基本上可以满足文章管理的多数场景,如果能够理解mysql表的设计,可以使用模型管理这个大杀器,

基本上能够想到的功能都能实现,最后再对【添加相关文章】功能进行设计和移植,模型功能能够再次爆发威力,进行各种关系映射。前台配合ajax和json,以及数据表的query函数可以整合实现相当复杂的功能和页面。

1,模型管理中添加一个万能字段。

然后在表单栏中填写:

注意上面的标红字体,需要和相关参数关联

2,在文章修改页面添加如下函数

function show_rt(modelid,id) {

$.getJSON("?<?php echo "token=".$_SESSION['token'];?>&m=content&c=content&a=rt_getjson_ids&modelid="+modelid+"&id="+id, function(json){

var newrt_ids = '';

if(json==null) {

alert('没有添加相关文章');

return false;

}

$.each(json, function(i, n){

newrt_ids += "

· "+n.title+" ";

});

$('#rt_text').html(newrt_ids);

});

}

//移除相关文章

function remove_rt(sid,id) {

var rt_ids = $('#rt').val();

if(rt_ids !='' ) {

$('#'+sid).remove();

var r_arr = rt_ids.split('|');

var newrt_ids = '';

$.each(r_arr, function(i, n){

if(n!=id) {

if(i==0) {

newrt_ids = n;

} else {

newrt_ids = newrt_ids+'|'+n;

}

}

});

$('#rt').val(newrt_ids);

}

}

3,在content.php中填写如下函数

public function public_rtlist() {

ec_main::get_lib_c('format','',0);

$show_header = '';

$model_cache = getcache('model','commons');

if(!isset($_GET['modelid'])) {

showmessage(L('please_select_modelid'));

} else {

$page = intval($_GET['page']);

$modelid = intval($_GET['modelid']);

$this->db->set_model($modelid);

$where = '';

if($_GET['catid']) {

$catid = intval($_GET['catid']);

$where .= "catid='$catid'";

}

$where .= $where ? ' AND status=99' : 'status=99';

if(isset($_GET['keywords'])) {

$keywords = trim($_GET['keywords']);

$field = $_GET['field'];

if(in_array($field, array('id','title','keywords','description'))) {

if($field=='id') {

$where .= " AND `id` ='$keywords'";

} else {

$where .= " AND `$field` like '%$keywords%'";

}

}

}

$infos = $this->db->listinfo($where,'',$page,12);

$pages = $this->db->pages;

include $this->admin_tpl('rtlist');

}

}

public function rt_getjson_ids() {

$modelid = intval($_GET['modelid']);

$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),'rt');

if($r['rt']) {

$rt = str_replace('|', ',', $r['rt']);

$rt = trim($rt,',');

$where = "id IN($rt)";

$infos = array();

$this->db->table_name = 'ec_chang';

$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);

}

}

5增加模板rtlist.tpl.php[content/tpl]

defined('IN_ADMIN') or exit('No permission resources.');

include $this->admin_tpl('header','admin');

?>

><?php echo L('title');?>

><?php echo L('keywords');?>

><?php echo L('description');?>

>ID

<?php echo $r['title'];?><?php echo $this->categorys[$r['catid']]['catname'];?><?php echo format::date($r['inputtime']);?>

.line_ff9966,.line_ff9966:hover td{

background-color:#FF9966;

}

.line_fbffe4,.line_fbffe4:hover td {

background-color:#fbffe4;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值