1. 程式人生 > >thinkphp5使用load和use引入第三方類

thinkphp5使用load和use引入第三方類

一、使用Load

1、在extend資料夾下面放extend/mail/phpmailer.php檔案;

2、在applicatioon/index.php檔案中寫入

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

3、在index控制器中引用

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

二、使用use

1、在extend資料夾下面放extend/mail/phpmailer.php檔案;

2、開啟phpmailer.php檔案,並在頭部新增

namespace mail;

3、在index控制器中引用

use mail;//此步驟相當於引入了所有名稱空間為mail的檔案

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