源码为ThinkAdmin V4.0(thinkphp5.1.35)
为了适合win做开发,环境采用的docker centos7.6
踩坑记录:
1.安装topthink/think-swoole报错:
The "https://packagist.laravel-china.org/packages.json" file could not be downloaded: Peer certificate CN=*.phphub.org' did not match expected CN=packagist.laravel-china.org'
修改当前工程的源地址(仅修改当前工程的,本人尝试过修改全局,无效果)
仅修改当前工程配置,仅当前工程可使用该镜像地址:composer config repo.packagist composer https://mirrors.aliyun.com/composer/
取消配置:composer config --unset repos.packagist
2.swoole版本
起初安装的是swoole4.4.0,运行时报错:Uncaught think\Exception: method not exists:think\Request->filterValue
经过查找发现问题:
开启RuntimeHook时, 将替换函数array_walk, array_walk_recursive为swoole实现的版本
这是swoole4.4.0新特性里面的说明,因为array_walk_recursive函数的替换,导致源码无法运行,需降低swoole的版本为:swoole4.3.6
指定版本安装方法:pecl install https://pecl.php.net/get/swoole-4.3.6.tgz
这里查找指定的版本列表:https://pecl.php.net/package/swoole
3.执行pecl install swoole报错:
No releases available for package "pecl.php.net/swoole"
可先执行:pecl search swoole
根据提示做update操作
4.报错:ERROR: unable to unpack /tmp/pear/download/swoole-4.4.3.tgz
下载不完整导致,可删除已下载的源码包,重新下载。
5.swoole里面不能够使用thinkphp里面原生路由的写法
如:gopher.cc/s=index/test/test
必须写成:gopher.cc/index/test/test
ThinkAdmin里面,\public\static\plugs\plupload\build.js ajax请求时写死的,带有s=,需要自己去掉才行。
6.不支持request获取get或post值
修改方法:
①不适用request,get就是get,post就是post
②修改think-swoole代码
\vendor\thinkphp\library\think\Request.php
添加方法:
- {
-     $this->request = $request;
-     return $this;
- }
\vendor\topthink\think-swoole\src\Application.php
- $this->request->withHeader($header) 
-     ->withServer($_SERVER) 
-     ->withGet($_GET) 
-     ->withPost($_POST) 
-     ->withCookie($_COOKIE) 
-     ->withInput($request->rawContent()) 
-     ->withFiles($_FILES) 
-     ->setBaseUrl($request->server['request_uri']) 
-     ->setUrl($request->server['request_uri'] . (!empty($request->server['query_string']) ? '&' . $request->server['query_string'] : '')) 
-     ->setHost($request->header['host']) 
修改为:
- $this->request->withHeader($header)
-     ->withServer($_SERVER)
-     ->withGet($_GET)
-     ->withPost($_POST)
-     ->withRequest($_GET ?? $_POST)
-     ->withCookie($_COOKIE)
-     ->withInput($request->rawContent())
-     ->withFiles($_FILES)
-     ->setBaseUrl($request->server['request_uri'])
-     ->setUrl($request->server['request_uri'] . (!empty($request->server['query_string']) ? '&' . $request->server['query_string'] : ''))
-     ->setHost($request->header['host'])
7.修改文件:\vendor\topthink\think-swoole\src\Application.php
$response->write($content);
修改为:
- if ($content != ""){
-     $response->write($content);
- }
不然在操作的时候,swoole日志里面会是满满的报错信息
8.修改文件:\public\static\admin.js
- $body.on('submit', 'form.form-search', function () {
-     var url = str.replace(/&?page=\d+/g, ''); var split = url.indexOf('?') === -1 ? '?' : '&';
-     if ((this.method || 'get').toLowerCase() === 'get') {
-         return window.location.href = '#' + $.menu.parseUri(url + split + $(this).serialize());
-     }
-     $.form.load(url, this, 'post');
- });
修改为:
- $body.on('submit', 'form.form-search', function () {
-     var str = $(this).attr('action').replace('&', '?');
-     var url = str.replace(/&?page=\d+/g, ''); var split = url.indexOf('?') === -1 ? '?' : '&';
-     if ((this.method || 'get').toLowerCase() === 'get') {
-         return window.location.href = '#' + $.menu.parseUri(url + split + $(this).serialize());
-     }
-     $.form.load(url, this, 'post');
- });
不然数据条件搜索的时候回报错
- $.vali.listen = function () {
-     $('form[data-auto]').map(function () {
-         if ($(this).attr('data-listen') !== 'true') $(this).attr('data-listen', 'true').vali(function (data) {
-             var call = $(this).attr('data-callback') || '_default_callback';
-             var type = this.getAttribute('method') || 'POST', tips = this.getAttribute('data-tips') || undefined;
-             var time = this.getAttribute('data-time') || undefined, href = this.getAttribute('action') || window.location.href;
-             $.form.load(href, data, type, window[call] || undefined, true, tips, time);
-         });
-     });
- };
- $.vali.listen = function () {
-     $('form[data-auto]').map(function () {
-         if ($(this).attr('data-listen') !== 'true') $(this).attr('data-listen', 'true').vali(function (data) {
-             var call = $(this).attr('data-callback') || '_default_callback';
-             var type = this.getAttribute('method') || 'POST', tips = this.getAttribute('data-tips') || undefined;
-             var time = this.getAttribute('data-time') || undefined, href = this.getAttribute('action') || window.location.href;
-             href = href.replace("&", "?");
-             $.form.load(href, data, type, window[call] || undefined, true, tips, time);
-         });
-     });
- };
- 'table'	=>	[
- 	// 定义最大记录数
- 	'size'	=>	1024,
-     // 字段类型定义(目前仅支持 string int 和 float类型)
-     'column'	=>[
-     	'data'	=>	['string',255], // 字符串类型 长度为255个字节
-         'expire'=> ['int',8], // 整型 长度为8
-     ],
- ],


