今天在composer安装图像处理扩展时,同时thinkphp的版本升级到了v5.0.11最新版。
安装完成后运行项目发现直接报错,而且没有记录log、没有提示信息。这也太坑了吧。
于是从入口文件开始排查原因,最后发现只要是验证码的类库文件出现了bug。
首先找到您的项目/vendor/topthink/think-captcha/src目录。
首先打开helper.php
找到头几行代码
Route::get('captcha/[:id]', "\think\captcha\CaptchaController@index");
Validate::extend('captcha', function ($value, $id = '') {
return captcha_check($value, $id);
});
Validate::setTypeMsg('captcha', ':attribute错误!');
如果是使用phpstorm这类比较智能的ide,可以很明显的发现错误,少些了命名空间。
更改如下
thinkRoute::get('captcha/[:id]', "\think\captcha\CaptchaController@index");
thinkValidate::extend('captcha', function ($value, $id = '') {
return captcha_check($value, $id);
});
thinkValidate::setTypeMsg('captcha', ':attribute错误!');
然后是这行代码
function captcha_src($id = '')
{
return Url::build('/captcha' . ($id ? "/{$id}" : ''));
}
还是命名空间的问题、更改如下
function captcha_src($id = '')
{
return thinkUrl::build('/captcha' . ($id ? "/{$id}" : ''));
}
然后是最后一个函数
function captcha_check($value, $id = '')
{
$captcha = new thinkcaptchaCaptcha((array) Config::pull('captcha'));
return $captcha->check($value, $id);
}
还是命名空间的问题 并且Config类没有pull方法、推测应该是Cache类、更改如下
function captcha_check($value, $id = '')
{
$captcha = new thinkcaptchaCaptcha((array) thinkCache::pull('captcha'));
return $captcha->check($value, $id);
}
然后找到CaptchaController.php
还是命名空间的问题
use thinkfacadeConfig;
这是什么鬼啊。更改如下
use thinkCache;
然后是index方法
public function index($id = "")
{
$captcha = new Captcha((array) Config::pull('captcha'));
return $captcha->entry($id);
}
Config类并没有一个叫pull的静态方法、更改入下
public function index($id = "")
{
$captcha = new Captcha((array) Cache::pull('captcha'));
return $captcha->entry($id);
}
最后是Captcha.php
同样的命名空间的问题
use thinkfacadeSession;
更改如下
use thinkSession;
改完这些项目应该就能正常运行了。