Yii 2.0: yii2-twilio

This component is YII2 wrapper for Twilio PHP SDK
2 followers

This component is YII2 wrapper for Twilio PHP SDK.

Requirements

Yii 2.0 or above

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist filipajdacic/yii2-twilio "*"

or add

"filipajdacic/yii2-twilio": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by putting this in your config:

'components' => array(
    ...
    'Yii2Twilio' => array(
        'class' => 'filipajdacic\yiitwilio\YiiTwilio',
        'account_sid' => 'YOUR_TWILIO_ACCOUNT_SID_HERE',
        'auth_key' => 'YOUR_TWILIO_AUTH_KEY_HERE', 
    ),
    ...
);

After you have configured a component, you can use it for example in this way:

$twilioService = Yii::$app->Yii2Twilio->initTwilio();
 
    try {
        $message = $twilioService->account->messages->create(array(
            "From" => "+12345678901", // From a valid Twilio number
            "To" => "+12345678901",   // Text this number
            "Body" => "Hello from my Yii2 Application!",
        ));
    } catch (\Services_Twilio_RestException $e) {
            echo $e->getMessage();
    }

For more SDK functions and usage documentation feel free to visit official Twilio PHP SDK documentation section here.

Resources

...external resources for this extension...

If you have any questions, feel free to ask.

Total 2 comments

#19978 report it
Filip Ajdacic at 2016/11/15 07:15am
twill and yii2 setup

@djn Yes, it will work as long as you have active internet connection and doesen't have some kind of firewall that may cause a problems. But, in fact, it will work.

#19977 report it
djn at 2016/11/15 07:06am
twill and yii2 setup

Will the setup on twill work on a localhost dev server?

Thanks, Dan

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet