php - TP3.2 problem loading third-party libraries
黄舟
黄舟 2017-06-27 09:17:46
0
1
881

Third-party libraries are often used in thinkphp development. I usually put the third-party class libraries in the Application/Codebase/ directory. Because many third-party libraries do not have namespaces, I don't want to add namespaces one by one. How to load the class library file in the Codebase directory?
For example, my tp project directory structure

I want to load the class.phpmailer.php file (without namespace) under CodebasephpMailer. What should I do? It is best to load it automatically.
I read the manual to use class library mapping. I created a new alias.php in commonconf, the code is as follows

return array(    
    'Codebase\phpMailer'        =>    APP_PATH.'/Codebase/phpMailer/class.phpmailer.php',    
    );

Then I $obj=new CodebasephpMailerPHPMailer();

in indexcontroller

Error: Class 'CodebasephpMailerPHPMailer' not found
How to deal with it? There is another question. The class loading error message in TP usually shows this error. How do I know which file it is looking for the class in? I can’t see the specific path information, so it is difficult to troubleshoot.

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
typecho
在引入的文件中加个命名空间
namespace Codebase\Phpmailer;

使用的时候就
use Codebase\Phpmailer\Phpmailer;

请注意你的首字母大小写,以及不是class.phpmailer.php,而是Phpmailer.class.php
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template