thinkphp5使用load和use引入第三方类(转载)

一、使用Load

1、在extend文件夹下面放extend/mail/phpmailer.php文件;

2、在applicatioon/index.php文件中写入

define('EXTEND_PATH', '../extend/');
  • 1

3、在index控制器中引用

use think\Loader;
Loader::import('mail\PHPMailer', EXTEND_PATH);
$mail=new PHPMailer();
  • 1
  • 2
  • 3

二、使用use

1、在extend文件夹下面放extend/mail/phpmailer.php文件;

2、打开phpmailer.php文件,并在头部添加

namespace mail;
  • 1

3、在index控制器中引用

use mail;//此步骤相当于引入了所有命名空间为mail的文件

$mail=new \mail\PHPMailer();//PHPMailer is a name of class;

猜你喜欢

转载自blog.csdn.net/jb_home/article/details/81037829