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

步骤
1、下载安装captcha,(注意TP5.1是2.0版本的)
2、拿到think-captcha放到verndor/topthink下
3、打开vendor/composer/autoload_psr4.php
4、composer下添加autoload_files.php
5、编辑autoload_static.php
6、编辑autoload_real.php
7、好了,可以正常调用了
1、下载安装captcha,(注意TP5.1是2.0版本的)
composer require topthink/think-captcha 2.*

2、拿到think-captcha放到verndor/topthink下


3、打开vendor/composer/autoload_psr4.php
加入 ‘think\captcha\’ => array($vendorDir . ‘/topthink/think-captcha/src’),
autoload_psr4.php

return array(
'think\\composer\\' => array($vendorDir . '/topthink/think-installer/src'),
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
'app\\' => array($baseDir . '/application'),
);
1
2
3
4
5
4、composer下添加autoload_files.php


autoload_files.php

<?php

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
'1cfd2761b63b0a29ed23657ea394cb2d' => $vendorDir . '/topthink/think-captcha/src/helper.php',
);
1
2
3
4
5
6
7
8
5、编辑autoload_static.php
添加以下代码


public static $files = array (
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
);
...
array (
'think\\composer\\' => 15,
'think\\captcha\\' => 14,
),
...
'think\\composer\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-installer/src',
),
'think\\captcha\\' =>
array (
0 => __DIR__ . '/..' . '/topthink/think-captcha/src',
),
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
6、编辑autoload_real.php
查看自己autoload_static.php类名,并添加添加函数composerRequirec6c13346c3bda597899f762f41f5ad54调用

 


public static function getLoader()
{

...
$loader->register(true);

if ($useStaticLoader) {
$includeFiles = Composer\Autoload\自己的autoload_static.php的类名::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirec6c13346c3bda597899f762f41f5ad54($fileIdentifier, $file);
}

return $loader;
}

//添加函数
function composerRequirec6c13346c3bda597899f762f41f5ad54($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
7、好了,可以正常调用了

结果:

————————————————
版权声明:本文为CSDN博主「RCX明」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ruancexiaoming/article/details/89606563

posted @ 2022-07-20 16:42  @菜鸟爱学习@  阅读(870)  评论(0编辑  收藏  举报