解决升级Thinkphp v5.0.11后项目报错打不开的问题

17-10-11 16:57 字数 1579 阅读 2918 已编辑

今天在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;    

改完这些项目应该就能正常运行了。

0人点赞>
关注 收藏 改进 举报
1 条评论
排序方式 时间 投票
Up骚年

看了下官网的升级指导,具体的安全升级方法大家可以参考官网https://www.kancloud.cn/manual/thinkphp5_1/354155
这个解决方案只是解决了我的问题,但是可能并不适用你。生产环境请慎重

请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 128.26万
私信