search

Home  >  Q&A  >  body text

php - TP3.2 problem loading third-party libraries

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.

黄舟黄舟2777 days ago963

reply all(1)I'll reply

  • typecho

    typecho2017-06-27 09:19:46

    在引入的文件中加个命名空间
    namespace Codebase\Phpmailer;
    
    使用的时候就
    use Codebase\Phpmailer\Phpmailer;
    
    请注意你的首字母大小写,以及不是class.phpmailer.php,而是Phpmailer.class.php

    reply
    0
  • Cancelreply