### Alipay Instant Payment Example
Source: https://help.jizhicms.cn/topay.html
Example of how to construct a URL for an instant Alipay payment. Ensure all required parameters are correctly set for the transaction.
```URL
http://您的网站域名/mypay/topay?tid=1&id=1&num=1&username=测试&email=123456@qq.com&address=北京朝阳区xxx号&tel=13900xxxx&ptype=1
```
--------------------------------
### Plugin Installation (PluginsController.php)
Source: https://help.jizhicms.cn/plugins-hook.html
Handles the installation process for a Jizhi CMS plugin, including registering a controller hook. This function is called when a plugin is installed via the backend.
```php
//执行SQL语句在此处处理,或者移动文件也可以在此处理
public function install(){
//下面是新增test表的SQL操作
/*
$table = 'test';
$sql = "CREATE TABLE IF NOT EXISTS `".DB_PREFIX.$table."` (
`id` int(11) unsigned NOT NULL auto_increment,
`tid` int(11) DEFAULT 0,
`orders` int(11) DEFAULT 0,
`comment_num` int(11) DEFAULT 0,
`htmlurl` varchar(100) DEFAULT NULL,
PRIMARY
KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
$x = M()->runSql($sql);
*/
//转移一个文件到另一个文件下面
/**
* 方法1:将当前目录下的tpl/test.html 转移到 根目录static/test.html (需要确定转移的文件目录已存在)
* copy(APP_PATH.APP_HOME.'/exts/test/tpl/test.html',APP_PATH.'static/test.html')
* 方法2:将当前目录下的file文件夹下面所有文件(只是文件,不包含文件夹) 转移到 根目录static下面 (需要确定转移的文件目录已存在)
* $this->removeFile(APP_PATH.APP_HOME.'/exts/test/file',APP_PATH.'static');
* 方法3:将当前目录下的file文件夹下面所有文件(包含文件夹) 转移到 根目录static下面
* $this->recurse_copy(APP_PATH.APP_HOME.'/exts/test/file',APP_PATH.'static');
*/
//备份当前数据库
/**
* $this->JZ_backup();
*/
/**
这里进行注册 hook
**/
$ww = [];
$ww['module'] = 'home';
$ww['controller'] = 'Home';//HomeController前台主要入口控制器
$ww['action'] = 'jizhi';//主入口函数
$ww['hook_controller'] = 'NewTest';//我们需要创建的控制器 NewTestController
$ww['hook_action'] = 'index';//需要写的函数
$ww['all_action'] = 1;//这个标识,HomeController下面的所有方法,是否都执行我的这个函数,1是0否
$ww['isopen'] = 1;//开放这个钩子,必须写1
$ww['plugins_name'] = 'newtest';//我们这个插件文件夹名字
$ww['addtime'] = time();//当前时间,默认必须写
M('hook')->add($ww);
setCache('hook',null);//重置钩子,只要注册了钩子就必须重置才会执行
return true;
}
```
--------------------------------
### PHP Plugin Controller Example
Source: https://help.jizhicms.cn/plugins-hook.html
This is an example of a Jizhi CMS plugin controller. It demonstrates how to check if a plugin is enabled, retrieve its configuration, and display a message.
```php
namespace app\home\plugins;
use app\home\c\CommonController;
class NewTestController extends CommonController
{
function index()
{
echo '这是一个插件页面!';
//查询插件是否已经开启
$plugins = M('plugins')->find(['filepath'=>'newtest','isopen'=>1]);
if($plugins){
$config = json_decode($plugins['config']);//后台存储的json,所以要专为数组形式
$this->newtest = $config;//将插件赋值到模板中
}
else{
Error('插件未开启!');
}
}
}
```
--------------------------------
### Example Response for Get User Info API
Source: https://help.jizhicms.cn/app/getuserinfo.html
This is a sample JSON response when successfully retrieving user information. It includes user details like ID, username, contact information, and group settings.
```json
{
"code": 0,
"msg": "success",
"data": {
"id": "99",//用户ID
"molds": "member_group",//用户组模型
"username": "ylrrja",//随机生成的用户名
"openid": null,//公众号openid
"pass": "8718a19eabec0174b7bc256254c336a5",//密码加密字符串
"token": null,//安全token
"sex": "0",//性别:0未知1男2女
"gid": "1",//用户组ID
"litpic": null,//头像
"tel": "13800138008",//手机号
"jifen": 1,//积分
"likes": null,//已作废
"collection": null,//已作废
"money": "0.00",//钱包
"email": "12312312@qq.com",//邮箱
"address": null,//地址
"province": null,//省份
"city": null,//城市
"regtime": "1724393605",//注册时间戳
"logintime": "0",//登录时间
"isshow": "1",//是否显示
"signature": null,//签名
"birthday": null,//生日
"follow": null,//已作废
"fans": "0",//粉丝数
"ismsg": "1",//是否接收信息提醒
"iscomment": "1",//是否允许评论提醒
"iscollect": "1",//是否允许收藏提醒
"islikes": "1",//是否允许点赞提醒
"isat": "1",//是否允许@提醒
"isrechange": "1",//是否允许交易提醒
"pid": "0",//父类ID,推荐人
"uploadsize": "50",//允许上传的总容量50MB,单位MB
"name": "注册会员",//分组名称
"description": "前台会员分组,最低等级分组",//分组描述
"paction": ",Message,Comment,User,Order,Home,Common,Uploads,",//前台权限
"isagree": "1",//是否允许登录
"ischeckmsg": "1",
"addtime": "0",//分组添加时间
"orders": "0",//排序
"discount": "0.00",//折扣
"discount_type": "0"//折扣类型
}
}
```
--------------------------------
### Loop Limit with Offset
Source: https://help.jizhicms.cn/loop-limit.html
Specify a starting point and count for the loop output using 'limit="start,count"'. The database counts from 0, so 'limit="0,10"' starts from the first item and displays 10. 'limit="1,10"' starts from the second item and displays 10.
```Jizhicms Template
{loop table="表名" tid="栏目ID" isshow="1" limit="1,10" as="v"}
{/loop}
```
--------------------------------
### Example Response for Get Single Content
Source: https://help.jizhicms.cn/app/getcontents.html
This is an example of a successful response from the Get Single Content API, indicating the structure of the returned data.
```json
{
"code": 0,
"msg":"success",
"data":{}
}
```
--------------------------------
### User Registration API Request Example
Source: https://help.jizhicms.cn/app/register.html
Example of how to make a POST request to the user registration API using curl. It includes all required parameters like phone number, password, and verification code.
```bash
curl -X POST -d "ajax=1&tel=13800138000&email=123456@qq.com&password=123456&repassword=123456&vercode=abcd" https://demo.jizhicms.cn/login/register
```
--------------------------------
### SQL Cache Query Examples
Source: https://help.jizhicms.cn/sqlcache.html
Examples of SQL queries to be used with the Jizhicms cache for different search criteria. Ensure strings use English single quotes.
```sql
id in(1,2,3) or tid in(2,3,4)
```
```sql
title like '%网站建设%'
```
```sql
(title like '%网站建设%' or body like '%网站建设%')
```
```sql
title='网站建设'
```
--------------------------------
### Example cURL Request for User Login
Source: https://help.jizhicms.cn/app/login.html
Demonstrates how to make a POST request to the user login endpoint using cURL, including all required parameters.
```bash
curl -X POST -d "ajax=1&tel=13800138000&email=123456@qq.com&password=123456&vercode=abcd" https://demo.jizhicms.cn/login/index
```
--------------------------------
### Jizhicms AJAX List Template Example
Source: https://help.jizhicms.cn/ajax.html
This is an example of an AJAX list template (`ajax_list_*.html`) for Jizhicms. It iterates through a list of articles, displaying their image, title, date, author, description, and a 'Learn More' button. This is a template structure and not executable JavaScript.
```html
{if($lists)}
{foreach $lists as $v}
{/foreach}
{/if}
```
--------------------------------
### Get Website System Configuration
Source: https://help.jizhicms.cn/wechat-miniprogram/wxdev.html
Uses the `util.AJAX` method to fetch website system configuration. It then updates the navigation bar title and sets local data with the retrieved configuration. Ensure `util.config.accesskey` is correctly set.
```javascript
// 获取网站配置信息
util.AJAX("/GetData/index", function (res) {
//正确获取数据
if(res.data.code==0){
var webconfig = [];
var len = res.data.data.length;
//对返回的数据进行封装成键值对的形式,方便调用
for(var i=0;i Array
(
[id] => 1
[classname] => 公司产品
[seo_classname] => 公司产品
[molds] => product
[litpic] =>
[description] =>
[keywords] =>
[body] =>
[orders] => 0
[orderstype] => 1
[isshow] => 1
[iscover] => 0
[pid] => 0
[gid] => 0
[htmlurl] => product
[lists_html] => list.html
[details_html] => details.html
[lists_num] => 9
[comment_num] => 0
[gourl] =>
[ishome] => 1
[isclose] => 0
[gids] =>
[lang] => cn
[haschild] => 1 //是否有下级
[level] => 0 //当前栏目的层级,0表示顶级
[url] => http://demo.jizhicms.cn/product.html
[children] => Array
(
//当前栏目的直系下级ID数组
[id] => Array
(
[0] => 6
[1] => 7
)
//当前栏目的直系下级栏目数组
[list] => Array
(
[0] => Array
(
[id] => 6
[classname] => 免费模板
[seo_classname] => 免费模板
[molds] => product
[litpic] =>
[description] =>
[keywords] =>
[body] =>
[orders] => 0
[orderstype] => 1
[isshow] => 1
[iscover] => 0
[pid] => 1
[gid] => 0
[htmlurl] => free
[lists_html] => list
[details_html] => details
[lists_num] => 9
[comment_num] => 0
[gourl] =>
[ishome] => 1
[isclose] => 0
[gids] =>
[lang] => cn
[haschild] =>
[level] => 1
[url] => http://demo.jizhicms.cn/free.html
[children] => Array
(
//当前栏目的直系下级ID数组
[id] => Array
(
)
//当前栏目的直系下级栏目数组
[list] => Array
(
)
//包含当前栏目和所有下级的栏目ID数组
[ids] => Array
(
[0] => 6
)
//所有下级的栏目数组
[lists] => Array
(
)
)
)
[1] => Array
(
...(栏目内容)
)
)
)
)
)
```
--------------------------------
### Nested Loop Example
Source: https://help.jizhicms.cn/loop.html
Demonstrates how to use nested 'loop' tags to display hierarchical data, such as articles within categories. Ensure distinct 'as' variables are used for each loop to prevent conflicts.
```html
{loop table="classtype" isshow="1" pid="0" as="v"}
{loop table="article" tid="$v['id']" isall="1" limit="10" as="vv"}
文章标题:{$vv['title']}
文章简介:{$vv['description']}
文章内容:{$vv['body']}
文章缩略图:{$vv['litpic']}
{/loop}
{/loop}
```
--------------------------------
### AJAX Member Registration Example
Source: https://help.jizhicms.cn/member-register.html
This JavaScript function demonstrates how to perform member registration using AJAX. It sends registration data to the server and handles the response, including success messages, errors, and redirects.
```javascript
function register(){
var tel = $("#r-tel").val();
var pass = $("#r-pass").val();
var repass = $("#r-repass").val();
if(tel==''){
layer.alert('手机号不能为空!');return false;
}
if(pass==''){
layer.alert('登录密码不能为空!');return false;
}
if(repass==''){
layer.alert('重复密码不能为空!');return false;
}
if(pass!=repass){
layer.alert('两次密码不同!');return false;
}
{if(!$webconf['closehomevercode'])}
var yzm = $("#r-yzm").val();
if(yzm==''){
layer.alert('验证码不能为空!');return false;
}
{else}
var yzm = '';
{/if}
$.post('/login/register',{tel:tel,repassword:repass,password:pass,vercode:yzm,ajax:1,autologin:1},function(res){
if(res.code==0){
layer.msg(res.msg,{icon: 6,time: 2000},function(){
//登录成功后的操作
window.location.href=res.url;
})
}else{
layer.msg(res.msg,{icon:5,time:2000});
var img = '/common/vercode?name=reg_vercode&'+Math.random();
$("#register-yzm").attr('src',img);
}
},'json')
return false;
}
```
--------------------------------
### Retrieving Configuration with webConf Function
Source: https://help.jizhicms.cn/label.html
The `webConf` function retrieves configuration settings. Pass the desired field name as an argument to get its value.
```JizhiCMS Template
{fun webConf('web_name')}
```
--------------------------------
### Article Likes/Unlikes API Response Examples
Source: https://help.jizhicms.cn/app/dolikes.html
Shows successful responses for liking and unliking an article. Use the /user/likesAction endpoint with POST/GET method.
```json
{
"code": 0,
"msg": "点赞成功",
"data":[]
}
```
```json
{
"code": 0,
"msg": "已取消点赞",
"data":[]
}
```
--------------------------------
### Initialize Database Backup Configuration
Source: https://help.jizhicms.cn/plugins-hook.html
Sets up the database connection configuration for backup operations, merging with existing configurations.
```PHP
$pconfig = array(
'host' =>DB_HOST,
'port' =>DB_PORT,
'user' =>DB_USER,
'password' =>DB_PASS,
'database' =>DB_NAME
);
$this->config = array_merge($this->config, $pconfig);
$this->handler = new
aquoPDO("mysql:host=".$this->config['host'].";port={\$ his->config['port']};dbname={\$ his->config['database']}", $this->config['user'], $this->config['password']);
$this->handler->query("set names utf8");
$this->backup();
```
--------------------------------
### Example cURL Request to Get User Info
Source: https://help.jizhicms.cn/app/getuserinfo.html
This snippet shows how to make a POST request using cURL to the Get User Info endpoint. Ensure you replace '12321312' with a valid token.
```bash
curl -X POST -d "ajax=1&token=12321312" https://demo.jizhicms.cn/user/userinfo
```
--------------------------------
### Get Single Content
Source: https://help.jizhicms.cn/app/getcontents.html
Retrieves a single content item based on its ID and model. Supports both POST and GET requests.
```APIDOC
## GET /user/getcontent
### Description
Retrieves a single content item using its ID and model identifier.
### Method
POST/GET
### Endpoint
/user/getcontent
### Parameters
#### Query Parameters
- **ajax** (number) - Required - Ajax return identifier, defaults to 1.
- **token** (string) - Required - User authorization key.
- **molds** (string) - Required - Model identifier.
- **id** (number) - Required - Content ID.
### Response
#### Success Response (0)
- **code** (integer) - Response code, 0 indicates success.
- **msg** (string) - Response message, e.g., "success".
- **data** (object) - Response object containing the content data upon success, or an empty array upon failure.
#### Response Example
```json
{
"code": 0,
"msg":"success",
"data":{}
}
```
### Error Codes
- **0**: Request successful.
- **1**: Request parameter error, e.g., incorrect format or missing parameters.
```
--------------------------------
### Example API Response for Upload Avatar
Source: https://help.jizhicms.cn/app/headimg.html
This is an example of a successful response from the upload avatar API, showing the returned URL and status code.
```json
{
"url": "/static/upload/2024/08/23/202408238633.png",
"code": 0
}
```
--------------------------------
### Displaying Thumbnails in Frontend Templates
Source: https://help.jizhicms.cn/plugins-imagethumbnail.html
These examples demonstrate how to output different sized images in your frontend templates using the `showpic` function. The default output is the original or medium-sized image, while 's' and 'l' specify small and large thumbnails, respectively.
```html
假设图片为:$v['litpic']
中图(默认图片):{$v['litpic']}或{fun showpic($v['litpic'])}或{fun showpic($v['litpic'],'d')}
小图:{fun showpic($v['litpic'],'s')}
大图:{fun showpic($v['litpic'],'l')}
```
--------------------------------
### Basic GET Request with jQuery
Source: https://help.jizhicms.cn/ajax.html
Use this snippet for simple GET requests to fetch data. Ensure jQuery is included before this code. The response is expected in JSON format.
```javascript
$.get('请求地址',{
请求参数
},function(res){
//只需成功后返回内容
console.log(res)
},'json')
```
--------------------------------
### Initiate Payment
Source: https://help.jizhicms.cn/topay.html
This endpoint allows users to directly initiate a payment for a product. It supports various payment types and collects necessary buyer information.
```APIDOC
## POST/GET mypay/topay
### Description
Initiates an immediate payment for a product, bypassing the shopping cart. It accepts product details and buyer information to process the payment.
### Method
POST/GET
### Endpoint
/mypay/topay
### Parameters
#### Path Parameters
None
#### Query Parameters
- **tid** (integer) - Required - Product category ID.
- **id** (integer) - Required - Product ID.
- **num** (integer) - Optional - Purchase quantity (default: 1).
- **username** (string) - Optional - Buyer's username (default: anonymous).
- **email** (string) - Optional - Buyer's email address (default: empty).
- **address** (string) - Optional - Buyer's shipping address (default: empty).
- **tel** (string) - Optional - Buyer's phone number (default: empty).
- **ptype** (integer) - Optional - Payment type (default: 1).
- 1: Alipay payment (dual-end)
- 2: WeChat payment (in-app, H5, PC scan code)
- 3: Wallet payment
- 4: Points payment
- 5: Alipay face-to-face payment
### Request Example
```json
{
"example": "http://yourdomain.com/mypay/topay?tid=1&id=1&num=1&username=test&email=123456@qq.com&address=Beijing Chaoyang District xxx&tel=13900xxxx&ptype=1"
}
```
### Response
#### Success Response (200)
- **Details**: Order details are processed and confirmation is sent via email if configured and provided.
#### Response Example
None explicitly provided in source.
```
--------------------------------
### Example Response for Modifying User Information
Source: https://help.jizhicms.cn/app/edituserinfo.html
This is an example of a successful response from the modify user information API. It indicates the operation was successful with a code of 0 and a success message.
```json
{
"code": 0,
"msg": "修改成功!",
"data":[]
}
```
--------------------------------
### WeChat Official Request for System Configuration
Source: https://help.jizhicms.cn/wechat-miniprogram/wxdev.html
Demonstrates how to make a POST request to the `/GetData/index` endpoint using `wx.request` to fetch system configuration. This method is suitable for direct WeChat API interactions. Ensure `util.config.appApiUrl` and `util.config.accesskey` are correctly configured.
```javascript
//微信自带请求
wx.request({
url:util.config.appApiUrl+'/GetData/index',
data:{ key: util.config.accesskey, model:"sysconfig"},
method:'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
dataType:'json',
success:function(res){
console.log(res);
}
});
```
--------------------------------
### Get User Info
Source: https://help.jizhicms.cn/app/getuserinfo.html
Retrieves user information using a GET request. Requires an 'ajax' parameter and a 'token' for authentication. Returns a comprehensive user object upon success.
```APIDOC
## GET /user/userinfo
### Description
Retrieves user information based on the provided token. This endpoint is used to fetch detailed user profile data.
### Method
GET
### Endpoint
/user/userinfo
### Parameters
#### Query Parameters
- **ajax** (number) - Required - Identifier for AJAX requests, defaults to 1.
- **token** (string) - Required - User authorization key obtained after login.
### Request Example
```
curl -X POST -d "ajax=1&token=12321312" https://demo.jizhicms.cn/user/userinfo
```
### Response
#### Success Response (200)
- **code** (integer) - Response code, 0 indicates success.
- **msg** (string) - Response message, e.g., "success".
- **data** (object) - User data object containing fields like id, username, email, etc. Returns an empty array on failure.
#### Response Example
```json
{
"code": 0,
"msg": "success",
"data": {
"id": "99",
"molds": "member_group",
"username": "ylrrja",
"openid": null,
"pass": "8718a19eabec0174b7bc256254c336a5",
"token": null,
"sex": "0",
"gid": "1",
"litpic": null,
"tel": "13800138008",
"jifen": 1,
"likes": null,
"collection": null,
"money": "0.00",
"email": "12312312@qq.com",
"address": null,
"province": null,
"city": null,
"regtime": "1724393605",
"logintime": "0",
"isshow": "1",
"signature": null,
"birthday": null,
"follow": null,
"fans": "0",
"ismsg": "1",
"iscomment": "1",
"iscollect": "1",
"islikes": "1",
"isat": "1",
"isrechange": "1",
"pid": "0",
"uploadsize": "50",
"name": "注册会员",
"description": "前台会员分组,最低等级分组",
"paction": ",Message,Comment,User,Order,Home,Common,Uploads,",
"isagree": "1",
"ischeckmsg": "1",
"addtime": "0",
"orders": "0",
"discount": "0.00",
"discount_type": "0"
}
}
```
### Error Handling
- **0**: Request successful.
- **1**: Request parameter error, e.g., incorrect or missing 'tel' format.
```
--------------------------------
### Display System Configuration Parameters
Source: https://help.jizhicms.cn/work/workready.html
Outputs various system configuration parameters defined in the backend. Ensure these are correctly set in the JizhiCMS admin panel.
```HTML
网站域名:{$webconf['domain']} //需要后台配置好
网站名:{$webconf['web_name']}
网站描述:{$webconf['web_desc']}
底部版权:{$webconf['web_copyright']}
网站备案:{$webconf['web_beian']}
网站手机:{$webconf['web_tel']}
400电话:{$webconf['web_tel_400']}
QQ:{$webconf['web_qq']}
邮箱:{$webconf['web_email']}
公司地址:{$webconf['web_address']}
自定义配置:{$webconf['自定义参数']} //后台显示的如:[ abc ] {$webconf['abc']}
模板资源路径:{$tpl} 解析路径:/staic/default(当前模板)/
```
--------------------------------
### 批量查询数据
Source: https://help.jizhicms.cn/model.html
使用findAll()函数查询多条数据。可指定查询条件、排序、字段和数量限制。返回查询结果数组。常用于获取列表数据。
```php
{php
$lists = M('article')->findAll(['isshow'=>1],'hits desc',null,10);
/}
{foreach $lists as $v}
ID:{$v['id']}
标题:{$v['title']}
链接:{fun gourl($v)}//链接需要使用链接创建方法获取url,可以从内置函数这个章节找到方法
{/foreach}
```
--------------------------------
### Single Entry Point Configuration
Source: https://help.jizhicms.cn/update-log.html
Configure a single entry point for both frontend and backend access through `index.php`. The default backend address is `/index.php/admins`. The `admins` identifier can be modified within `index.php`.
```php
> 单入口:进入前后台都通过`index.php`,也可以通过自定义入口文件进行指定,默认后台地址:`/index.php/admins` 在 `index.php` 里面可以修改 `admins` 后台模块标识
```
--------------------------------
### Successful Article Deletion Response
Source: https://help.jizhicms.cn/app/delarticle.html
Example of a successful response when an article is deleted.
```json
{
"code": 0,
"msg": "删除成功",
"data":[]
}
```
--------------------------------
### Get All Table Names (MySQL)
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves a list of all table names from a MySQL database.
```PHP
else{
$sql = "SHOW TABLES";
}
$tables = M()->findSql($sql);
$ttable = array();
foreach($tables as $value){
foreach($value as $vv){
$ttable[] = $vv;
}
}
return $ttable;
```
--------------------------------
### Output Product List
Source: https://help.jizhicms.cn/loop.html
Fetches and displays a list of products from a specific category (ID 2). Similar to articles, `isall` includes products from sub-categories. Use `isshow` to filter by display status.
```html
{loop table="product" tid="2" isall="1" limit="10" isshow="1" as="v"}
商品标题:{$v['title']}
商品简介:{$v['description']}
商品内容:{$v['body']}
商品缩略图:{$v['litpic']}
商品价格:{$v['price']}
...
{/loop}
```
--------------------------------
### Get All Table Names (SQLite)
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves a list of all table names from a SQLite database.
```PHP
if(defined('DB_TYPE') && DB_TYPE=='sqlite'){
$sql = "select name from sqlite_master where type='table' order by name";
}
```
--------------------------------
### Delete Article
Source: https://help.jizhicms.cn/app/delarticle.html
Allows users to delete articles. Supports both POST and GET requests.
```APIDOC
## Delete Article
### Description
Users can delete articles using this endpoint. It supports both POST and GET request methods.
### Method
POST/GET
### Endpoint
/user/del
### Parameters
#### Query Parameters
- **ajax** (number) - Required - ajax return identifier, defaults to 1.
- **token** (string) - Required - User authorization key.
- **id** (number) - Required - The ID of the article to delete.
- **molds** (string) - Optional - Model identifier, defaults to 'article'.
### Request Example
```json
{
"ajax": 1,
"token": "your_auth_token",
"id": 123,
"molds": "article"
}
```
### Response
#### Success Response (200)
- **code** (integer) - Response code, 0 indicates success.
- **msg** (string) - Response message.
- **data** (object) - Response object, returns an empty array on success.
#### Error Response (e.g., 400)
- **code** (integer) - Response code, 1 indicates failure.
- **msg** (string) - Response message.
- **data** (object) - Response object, returns an empty array on failure.
### Response Example
```json
{
"code": 0,
"msg": "Deletion successful",
"data": []
}
```
```json
{
"code": 1,
"msg": "Deletion failed",
"data": []
}
```
### Error Codes
- **0**: Request successful, correct response.
- **1**: Request parameter error, such as incorrect or missing tel format.
```
--------------------------------
### Making a Request with wx.request
Source: https://help.jizhicms.cn/wechat-miniprogram/wxapi.html
This snippet demonstrates how to make a POST request to a backend API using the wx.request method. It includes setting the URL, data payload, method, content type header, and handling the success response.
```javascript
wx.request({
url:util.config.appApiUrl+'/GetData/index',
data:{ key: util.config.accesskey, model:"sysconfig"},
method:'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
dataType:'json',
success:function(res){
console.log(res);
}
});
```
--------------------------------
### Apache伪静态配置
Source: https://help.jizhicms.cn/rewrite.html
将此内容添加到Apache服务器根目录下的.htaccess文件中,以启用伪静态。
```apache
RewriteEngine on
RewriteBase /
#RewriteCond %{REQUEST_URI} !((.*).jpg|.jpeg|.bmp|.gif|.png|.js|.css|.tts|.woff )$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
#RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
RewriteRule ^(.*)$ index.php [E=PATH_INFO:$1,QSA,PT,L]
```
--------------------------------
### Failed Article Deletion Response
Source: https://help.jizhicms.cn/app/delarticle.html
Example of a failed response when an article deletion fails.
```json
{
"code": 1,
"msg": "删除失败",
"data":[]
}
```
--------------------------------
### Product Module Content Parameters
Source: https://help.jizhicms.cn/plugins-webapi.html
Parameters for publishing content to the Product module. Includes standard fields plus 'pictures_urls[]' for image galleries. Multiple image URLs can be submitted.
```plaintext
tid:[标签:栏目ID]
title:[标签:文章标题]
addtime:[标签:时间]
body:[标签:内容]
以下可以不传入
litpic:[标签:缩略图](默认自动提取内容缩略图)
seo_title:[标签:文章SEO标题]
keywords:[标签:关键词]
description:[标签:简介]
pictures_urls[]:[标签:图集1]
pictures_urls[]:[标签:图集2](一次提交多个,按需写入)
```
--------------------------------
### Get Table Creation DDL
Source: https://help.jizhicms.cn/plugins-hook.html
Fetches the SQL statement used to create a specific table.
```PHP
private function getDDL($table = '')
{
$sql = "SHOW CREATE TABLE `{$table}`";
$ddl = $this->query($sql)[0][1] . ';';
return $ddl;
```
--------------------------------
### Get Table Fields (MySQL)
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves column names for a given table in a MySQL database.
```PHP
else{
$sql = 'SHOW COLUMNS FROM '.DB_PREFIX.$table;
$list = M()->findSql($sql);
$isgo = true;
$fields = [];
foreach($list as $v){
$fields[]=$v['Field'];
}
}
return $fields;
```
--------------------------------
### Get Table Fields (SQLite)
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves column names for a given table in a SQLite database.
```PHP
if(defined('DB_TYPE') && DB_TYPE=='sqlite'){
$sql = "pragma table_info(".DB_PREFIX."$table)";
$list = M()->findSql($sql);
$fields = [];
foreach($list as $v){
$fields[]=$v['name'];
}
}
```
--------------------------------
### wx.request for GetData/index
Source: https://help.jizhicms.cn/wechat-miniprogram/wxapi.html
This snippet demonstrates how to make a POST request to the /GetData/index API endpoint using wx.request to fetch data. It includes common parameters like API key, model, and optional parameters for filtering and sorting.
```APIDOC
## POST /GetData/index
### Description
This endpoint is used to retrieve data from the system. It supports various parameters for filtering, sorting, and selecting specific fields.
### Method
POST
### Endpoint
/GetData/index
### Parameters
#### Query Parameters
- **key** (string) - Required - API access key.
- **model** (string) - Required - Identifier for the module to query.
- **limit** (integer) - Optional - Number of records to retrieve.
- **orders** (string) - Optional - Sorting criteria (e.g., 'id desc,addtime desc'). Defaults to 'id asc'.
- **fields** (string) - Optional - Comma-separated list of fields to retrieve (e.g., 'id,title,body'). Defaults to all fields.
- **isshow** (boolean) - Optional - Whether to query for displayed items.
- **tid** (integer) - Optional - Identifier for the category to query.
### Request Example
```json
{
"url": "/GetData/index",
"data": {
"key": "YOUR_API_KEY",
"model": "sysconfig"
},
"method": "POST",
"header": {
"content-type": "application/x-www-form-urlencoded"
}
}
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for successful return, 1 for request error.
- **data** (array) - An array containing the retrieved data.
#### Response Example
```json
{
"code": 0,
"data": [
// ... retrieved data objects ...
]
}
```
```
--------------------------------
### Get Table Data
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves all rows and columns from a specified table and formats them into SQL INSERT statements.
```PHP
private function getData($table = '')
{
$sql = "SHOW COLUMNS FROM `{$table}`";
$list = $this->query($sql);
//字段
$columns = '';
//需要返回的SQL
$query = [];
foreach ($list as $value)
{
$columns .= "`{$value[0]}`,";
}
$columns = substr($columns, 0, -1);
$data = $this->query("SELECT * FROM `{$table}`");
foreach ($data as $value)
{
$dataSql = '';
foreach ($value as $v)
{
if($v==='' || $v===null){
$dataSql .= " NULL,";
}else{
$dataSql .= "'{$v}',";
}
```
--------------------------------
### 在loop中判断不同属性标签
Source: https://help.jizhicms.cn/loop-jzattr.html
在循环输出文章时,使用`strpos`函数判断`jzattr`字符串是否包含特定的属性值(1:置顶, 2:最热, 3:推荐),并输出相应的标签。
```html
{loop table="article" isshow="1" limit="10" as="v"}
{if($v['jzattr'])}
{if(strpos($v['jzattr'],',1,')!==false)}置顶{/if}
{if(strpos($v['jzattr'],',2,')!==false)}最热{/if}
{if(strpos($v['jzattr'],',3,')!==false)}推荐{/if}
{/if}
{/loop}
```
--------------------------------
### IIS伪静态配置
Source: https://help.jizhicms.cn/rewrite.html
将此XML内容保存到IIS服务器根目录下的web.config文件中,以启用伪静态。
```xml
```
--------------------------------
### Get All Table Names
Source: https://help.jizhicms.cn/plugins-hook.html
Retrieves a list of all table names from the database using a 'SHOW TABLES' SQL query.
```PHP
private function getTables()
{
$sql = 'SHOW TABLES';
$list = $this->query($sql);
$tables = array();
foreach ($list as $value)
{
$tables[] = $value[0];
}
return $tables;
```
--------------------------------
### Getting Current URL with current_url Function
Source: https://help.jizhicms.cn/label.html
The `current_url` function returns the complete URL of the current page.
```JizhiCMS Template
{fun current_url()}
```
--------------------------------
### 输出非推荐内容
Source: https://help.jizhicms.cn/loop-jzattr.html
使用`sql`参数配合`jzattr not like '%,3,%' or jzattr is null`来筛选出不包含推荐属性(3)的文章。
```html
{php}
$sql = " (jzattr not like '%,3,%' or jzattr is null) ";
{/}
{loop table="article" sql="$sql" isshow="1" limit="10" as="v"}
{/loop}
```
--------------------------------
### 执行SQL查询数据
Source: https://help.jizhicms.cn/model.html
使用findSql()函数执行原生SQL查询语句。返回查询结果数组或false。需要包含完整的表名。适用于复杂查询或需要直接操作数据库的场景。
```php
{php
$lists = M()->findSql("select * from jz_article where id=1 and isshow=1");
/}
```
--------------------------------
### Getting Visitor IP with GetIP Function
Source: https://help.jizhicms.cn/label.html
The `GetIP` function retrieves the current visitor's IP address.
```JizhiCMS Template
{fun GetIP()}
```
--------------------------------
### Getting Current Template Name with get_template Function
Source: https://help.jizhicms.cn/label.html
The `get_template` function returns the name of the currently active template file.
```JizhiCMS Template
{fun get_template()}
```
--------------------------------
### Switching Languages via URL Parameter
Source: https://help.jizhicms.cn/mutilang.html
Explains how to switch between different language versions of the website by appending a language parameter to the URL.
```http
http://域名/?l=zh_cn
```
--------------------------------
### Get Comment Count for a Specific User
Source: https://help.jizhicms.cn/comment.html
Retrieves the number of comments made by a specific user. Requires 'isshow' and 'userid' parameters.
```php
{fun M('comment')->getCount(['isshow'=>1,'userid'=>1])}
```
--------------------------------
### 实例化模型并查询条数
Source: https://help.jizhicms.cn/model.html
使用M()函数实例化模型,并通过getCount()方法查询满足条件的数据条数。支持SQL字符串或数组作为条件。
```php
{php echo M('member')->getCount(['gid'=>1]);/}
```
```php
{php echo M('member')->getCount('gid=1');/}
```
```php
{php echo M('article')->getCount(['member_id'=>1]);/}
```
```php
{php echo M('article')->getCount('member_id=1');/}
```
```php
{php echo M('article')->getCount("title like '%极致%' ");/}
```
--------------------------------
### Check Collect API Success Response
Source: https://help.jizhicms.cn/app/checkCollect.html
Example of a successful response from the /user/checkCollect API, indicating the content has been collected (data: true).
```json
{
"code": 0,
"msg": "success",
"data": true
}
```