phpcms使用api引用模块并获取数据

1、引用模块

$db = pc_base::load_model('content_model');  // 引用数据库模型,phpcms/model下文件

pc_base::load_config('system'); // 引用配置,caches/configs下文件

pc_base::load_sys_class('mysql'); // 引用系统类,phpcms/libs/classes下文件

pc_base::load_sys_func('global'); // 引用系统函数库,phpcms/libs/functions下文件

 2、api内获取列表数据

<?php
defined('IN_PHPCMS') or exit('No permission resources.');

$db = pc_base::load_model('content_model');

$categorys = getcache('category_content_1','commons');
$catid = 6; // $_GET['catid'] = intval($_GET['catid']);
$category = $categorys[$catid];
$modelid = $category['modelid'];
$model_arr = getcache('model', 'commons');
$MODEL = $model_arr[$modelid];
unset($model_arr);
$db->set_model($modelid);
// echo '<pre>';
// print_r($db->pages);
// echo '</pre>';

$status = 99;
$where = 'catid='.$catid.' AND status='.$status;
$pageSize = $_GET['pageSize'];
$pageIndex = $_GET['pageIndex'];

//keyword 搜索
if(isset($_GET['keyword']) && !empty($_GET['keyword'])) {
	$type_array = array('title','description','username');
	$searchtype = intval($_GET['searchtype']);
	if($searchtype < 3) {
		$searchtype = $type_array[$searchtype];
		$keyword = strip_tags(trim($_GET['keyword']));
		$where .= " AND `$searchtype` like '%$keyword%'";
	} elseif($searchtype==3) {
		$keyword = intval($_GET['keyword']);
		$where .= " AND `id`='$keyword'";
	}
}

// 添加自定义搜索字段
if(isset($_GET['infotype']) && !empty($_GET['infotype'])){
	$infotype = $_GET['infotype'];
	if($infotype != 0){
		$where .= " AND `infotype`=$infotype";
	}
}



// $where = '', $order = '', $page = 1, $pagesize = 20, $key='', $setpages = 10,$urlrule = '',$array = array(), $data = '*'
$datas = $db->listinfo($where,'id desc',$pageIndex, $pageSize); //$_GET['page']);
$pages = $db->pages;
$count = $db->number;

exit(json_encode($datas));

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值