如何在Yii2动作中使用外部PHP类文件

时间:2015-03-02 13:56:42

标签: php file include yii2

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是我的根文件夹(高级)

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控制器功能中包含外部php calss文件。

1 个答案:

答案 0 :(得分:0)

通过Composer安装Twillio PHP sdk(在Yii2运行的根目录中):

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

它已添加到Yii2自动加载的库,然后在您的操作中执行:

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

See Twilio php sdk on packagist