Maison  >  Article  >  développement back-end  >  thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

WBOY
WBOYoriginal
2016-06-06 20:07:431722parcourir

你好,我在使用thinkphp3.2.3中,使用composer require ucsdmath/encryption这个加密包,在入口文件中引入了require './vendor/autoload.php';​
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
在ApplicationHomeControllerIndexController.class.php中也加入了use UCSDMathEncryptionEncryption;
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
可是在实例化中 $encryption = new Encryption('hello');
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
这是我的目录结构:
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

回复内容:

你好,我在使用thinkphp3.2.3中,使用composer require ucsdmath/encryption这个加密包,在入口文件中引入了require './vendor/autoload.php';​
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
在ApplicationHomeControllerIndexController.class.php中也加入了use UCSDMathEncryptionEncryption;
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
可是在实例化中 $encryption = new Encryption('hello');
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
这是我的目录结构:
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

同问一个问题。。
https://segmentfault.com/q/1010000005272111

放到入口文件之前引入试试

应该是你的入口文件引入位置的问题导致的。
根据你需求的包,修改的composer.json如下
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
然后composer update 之后,修改的入口文件
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

IndexController.class.php文件 修改成
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下

在浏览器中查看的,结果是这样滴:
thinkphp3.2.3如何自动加载composer中的包,请帮忙解决下
从这个报错来看,很明显你需要的类已经引入了,但是很遗憾,这个类的用法我不会,所以报错了!

希望这些对你有帮助

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn