ThinkPHP 5.1 致命错误: Class 'think\captcha\Captcha' not found?

ThinkPHP 5.1 致命错误: Class 'think\captcha\Captcha' not found?


 

(1)问题发生场景:

  使用图片验证码时,报验证码类未找到。


 

(2)解决方法:

  原文链接:TP5.1.35 致命错误: Class 'think\captcha\Captcha' not found的解决方法

  原文讲述的比较详细。


 

(3)个人简单总结:

  1、下载安装captcha,(注意TP5.1是2.0版本的)
    composer require topthink/think-captcha 2.*

    注意:这里执行命令时路径一定要对,会自动安装到正确的路径,就无需手动移动文件和修改文件了。
  2、执行下载命令后,一般会自动下载到vendor/topthink下,如果不在该目录下,移动到这个目录下。

  3、打开vendor/composer/autoload_psr4.php,检查是否配置think\captcha的路径。

    正确的是这样的:

return array(
    'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
    'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
    'app\\' => array($baseDir . '/application'),
);

 

  4、检查composer下autoload_files.php文件,看是否有验证码的配置。正确的是这样的:

return array(
    '1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
);

  5、如果以上都是正确的,无需修改,那么应该可以直接调用这个Captcha类了。

    如果以上操作都是手动修改的,请按照原文继续后续操作。

  

  最后,不仅要将记得将topthink/think-captcha目录上传到服务器,有关配置文件都提交到服务器,才能生效。


 

 

posted @ 2021-08-28 11:07  学知无涯  阅读(2046)  评论(0)    收藏  举报