目录
- 基本组件
- 获取单个配置信息
- 获取全部配置信息
- 打印调试
- 行为日志记录
- 微信接口验证及报错获取
- 解析 model 报错
- 生成二维码
- IP地址转地区
- Curl
- 中文转拼音
- Glide
// 注意$fildName 为你的配置标识,默认从缓存读取
Yii::$app->debris->config($fildName);
// 强制不从缓存读取
Yii::$app->debris->config($fildName, true);
// 注意默认从缓存读取
Yii::$app->debris->configAll();
// 强制不从缓存读取
Yii::$app->debris->configAll(true);
Yii::$app->debris->p();
/**
* 行为日志
*
* @param string $behavior 行为标识
* @param string $remark 备注 注意长度为255
* @param bool $noRecordData 是否记录 post 数据 [true||false]
* @throws \yii\base\InvalidConfigException
*/
Yii::$app->services->sys->log($behavior, $remark, $noRecordData)
// 默认直接报错
Yii::$app->debris->getWechatError($message);
// 如果想不直接报错并返回报错信息
$error = Yii::$app->debris->getWechatError($message, false);
// 注意 $firstErrors 为 $model->getFirstErrors();
Yii::$app->debris->analyErr($firstErrors);
$qr = Yii::$app->get('qr');
Yii::$app->response->format = Response::FORMAT_RAW;
Yii::$app->response->headers->add('Content-Type', $qr->getContentType());
return $qr->setText('www.rageframe.com')
->setLabel('2amigos consulting group llc')
->setSize(150)
->setMargin(7)
->writeString();
or
use Da\QrCode\QrCode;
$qrCode = (new QrCode('This is my text'))
->setSize(250)
->setMargin(5)
->useForegroundColor(51, 153, 255);
// 把图片保存到文件中:
$qrCode->writeFile(Yii::getAlias('@attachment') . '/code.png'); // 没有指定的时候默认为png格式
// 直接显示在浏览器
header('Content-Type: '.$qrCode->getContentType());
echo $qrCode->writeString();
use Zhuzhichao\IpLocationZh\Ip;
var_dump(Ip::find('171.12.10.156'));
输出结果
array (size=4)
0 => string '中国' (length=6)
1 => string '河南' (length=6)
2 => string '郑州' (length=6)
3 => string '' (length=0)
4 => string '410100' (length=6)
use linslin\yii2\curl;
$curl = new curl\Curl();
//get http://example.com/
$response = $curl->get('http://example.com/');
if ($curl->errorCode === null) {
echo $response;
} else {
// List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
switch ($curl->errorCode) {
case 6:
//host unknown example
break;
}
}
文档地址:https://github.com/linslin/Yii2-Curl
use Overtrue\Pinyin\Pinyin;
// 小内存型
$pinyin = new Pinyin(); // 默认
// 内存型
// $pinyin = new Pinyin('Overtrue\Pinyin\MemoryFileDictLoader');
// I/O型
// $pinyin = new Pinyin('Overtrue\Pinyin\GeneratorFileDictLoader');
$pinyin->convert('带着希望去旅行,比到达终点更美好');
// ["dai", "zhe", "xi", "wang", "qu", "lyu", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"]
$pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_TONE);
// ["dài","zhe","xī","wàng","qù","lǚ","xíng","bǐ","dào","dá","zhōng","diǎn","gèng","měi","hǎo"]
$pinyin->convert('带着希望去旅行,比到达终点更美好', PINYIN_ASCII_TONE);
//["dai4","zhe","xi1","wang4","qu4","lyu3","xing2","bi3","dao4","da2","zhong1","dian3","geng4","mei3","hao3"]
更多文档:https://github.com/overtrue/pinyin
Glide是一个用PHP编写的非常简单的按需图像处理库
注意:系统默认只能在storage下使用,已经基础配置完毕,但是系统内未安装,如果需要使用请先安装
php composer.phar require --prefer-dist trntv/yii2-glide
用法:
直接输出一个图像
Yii::$app->glide->outputImage('new-upload.jpg', ['w' => 100, 'fit' => 'crop'])
创建一个图像
Yii::$app->glide->makeImage('new-upload.jpg', ['w' => 100, 'fit' => 'crop'])
创建一个带签名才能访问的图像
Yii::$app->glide->createSignedUrl(['glide/index', 'path' => 'images/2018-12/27/image_154588883551485657.jpg', 'w' => 175]);
注意开启设置
storage/config/main.php
内的 glide 组件的signKey,否则无效
来源:https://github.com/trntv/yii2-glide
配套文档:http://glide.thephpleague.com/