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