PHP code example of zoujingli / think-library
1. Go to this page and download the library: Download zoujingli/think-library library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zoujingli / think-library example snippets
// 定义 MyController 控制器
class MyController extend \think\admin\Controller {
// 指定当前数据表名
protected $dbQuery = '数据表名';
// 显示数据列表
public function index(){
$this->_page($this->dbQuery);
}
// 当前列表数据处理
protected function _index_page_filter(&$data){
foreach($data as &$vo){
// @todo 修改原列表
}
}
}
// 列表展示
$this->_page($dbQuery, $isPage, $isDisplay, $total);
// 列表展示搜索器(按 name、title 模糊搜索;按 status 精确搜索)
$this->_query($dbQuery)->like('name,title')->equal('status')->page();
// 对列表查询器进行二次处理
$query = $this->_query($dbQuery)->like('name, title')->equal('status');
$db = $query->db(); // @todo 这里可以对db进行操作
$this->_page($db); // 显示列表分页
// 表单显示及数据更新
$this->_form($dbQuery, $tplFile, $pkField , $where, $data);
// 数据删除处理
$this->_deleted($dbQuery);
// 数据禁用处理
$this->_save($dbQuery, ['status'=>'0']);
// 数据启用处理
$this->_save($dbQuery, ['status'=>'1']);
// 配置默认存储方式
sysconf('storage.type','文件存储类型');
// 七牛云存储配置
sysconf('storage.qiniu_region', '文件存储节点');
sysconf('storage.qiniu_domain', '文件访问域名');
sysconf('storage.qiniu_bucket', '文件存储空间名称');
sysconf('storage.qiniu_is_https', '文件HTTP访问协议');
sysconf('storage.qiniu_access_key', '接口授权AccessKey');
sysconf('storage.qiniu_secret_key', '接口授权SecretKey');
// 生成文件名称(链接url或文件md5)
$filename = \think\admin\Storage::name($url, $ext, $prv, $fun);
// 获取文件内容(自动存储方式)
$result = \think\admin\Storage::get($filename);
// 保存内容到文件(自动存储方式)
$result = \think\admin\Storage::save($filename, $content);
// 判断文件是否存在
boolean \think\admin\Storage::has($filename);
// 获取文件信息
$result = \think\admin\Storage::info($filename);
//指定存储类型(调用方法)
$result = \think\admin\Storage::instance('local')->save($filename, $content);
$result = \think\admin\Storage::instance('qiniu')->save($filename, $content);
$result = \think\admin\Storage::instance('txcos')->save($filename, $content);
$result = \think\admin\Storage::instance('upyun')->save($filename, $content);
$result = \think\admin\Storage::instance('alioss')->save($filename, $content);
// 读取文件内容
$result = \think\admin\Storage::instance('local')->get($filename);
$result = \think\admin\Storage::instance('qiniu')->get($filename);
$result = \think\admin\Storage::instance('txcos')->get($filename);
$result = \think\admin\Storage::instance('upyun')->get($filename);
$result = \think\admin\Storage::instance('alioss')->get($filename);
// 生成 URL 访问地址
$result = \think\admin\Storage::instance('local')->url($filename);
$result = \think\admin\Storage::instance('qiniu')->url($filename);
$result = \think\admin\Storage::instance('txcos')->url($filename);
$result = \think\admin\Storage::instance('upyun')->url($filename);
$result = \think\admin\Storage::instance('alioss')->url($filename);
// 检查文件是否存在
boolean \think\admin\Storage::instance('local')->has($filename);
boolean \think\admin\Storage::instance('qiniu')->has($filename);
boolean \think\admin\Storage::instance('txcos')->has($filename);
boolean \think\admin\Storage::instance('upyun')->has($filename);
boolean \think\admin\Storage::instance('alioss')->has($filename);
// 生成文件信息
$resutl = \think\admin\Storage::instance('local')->info($filename);
$resutl = \think\admin\Storage::instance('qiniu')->info($filename);
$resutl = \think\admin\Storage::instance('txcos')->info($filename);
$resutl = \think\admin\Storage::instance('upyun')->info($filename);
$resutl = \think\admin\Storage::instance('alioss')->info($filename);
// 指定关键列更新($where 为扩展条件)
boolean data_save($dbQuery, $data, 'pkname', $where);
// 发起get请求
$result = http_get($url, $query, $options);
// 发起post请求
$result = http_post($url, $data, $options);
// 设置参数
sysconf($keyname, $keyvalue);
// 获取参数
$keyvalue = sysconf($kename);
// 自研 UTF8 字符串加密操作
$string = encode($content);
// 自研 UTF8 加密字符串解密
$content = decode($string);
use think\admin\extend\CodeExtend;
// 数据 AES-256-CBC 对称加密
$encrypt = CodeExtend::encrypt($content, $enckey);
// 数据 AES-256-CBC 对称解密
$content = CodeExtend::decrypt($encrypt, $enckey);
use think\admin\extend\CodeExtend;
// 文本转 UTF8 编码
$content = CodeExtend::text2utf8($content)
use think\admin\extend\CodeExtend;
// 文本 Base64 URL 编码
$safe64 = CodeExtend::enSafe64($content)
// 文本 Base64 URL 解码
$content = CodeExtend::deSafe64($safe64)
use think\admin\extend\CodeExtend;
// 数据压缩 ( 内容越大效果越好 )
$enzip = CodeExtend::enzip($content)
// 数据解压 ( 内容越大效果越好 )
$content = CodeExtend::dezip($enzip)
use think\admin\extend\CodeExtend;
// 二维数组 转为 立体数据结构,需要存在 id 及 pid 关系
$tree = CodeExtend::arr2tree($list);
// 二维数组 转为 扁平数据结构,需要存在 id 及 pid 关系
$tree = CodeExtend::arr2table($list);