2015-03-02 36 views
0
I want to implement twillio API in Yii2. 
On submit form SMS should be sent. 

I placed all twillio library code in advanced yii2 app in : 

rr.lcl/library/twilli_lib/ 

rr.lcl是我的根文件夾(高級)如何使用外部的PHP類文件中Yii2行動

Here is my function: 

public function actionSendtestsms($id) { 
require($_SERVER['DOCUMENT_ROOT'].'/rr.lcl/library/twilio-php-master/Services/Twilio.php') 
     $client = new Services_Twilio($account_sid, $auth_token); 

} 

如何包括Yii2控制器功能外CALSS PHP文件。

回答

0

通過Composer安裝Twillio PHP SDK(在Yii2運行的根):

php /path/to/composer.phar require 'twilio/sdk:4.2.1' 

它添加libarary到Yii2自動加載後,在你的行動簡單地做:

public function actionSendtestsms($id) { 
     $client = new Services_Twilio($account_sid, $auth_token); 
} 

See Twilio php sdk on packagist

+0

感謝您的重播,但問題已通過Curl解決 – prad 2015-06-16 09:19:02

+1

請確保添加反斜槓或它將查找控制器,例如$ client = new \ Services_Twilio($ account_sid,$ auth_token); – 2016-01-09 21:06:53

相關問題