Adding Twilio To Yii 1.1 Project


I have added the twilio library ( from github) to yii 1.1.14 but in order to get it to work I had to make a change to the YiiBase.php file.

with a simple PHP page (outside of yii) and the twilio folder in the same folder as the php file, the twilio functions work perfectly.

I followed steps found at to load the library in the vendor section.

Inside YII, I created the following structure:








I created the CommsController.php file:



class CommsController extends Controller


        public $sid = "<img src='' class='bbc_emoticon' alt='???' />?"; // Your Account SID from

        public $token = "<img src='' class='bbc_emoticon' alt='???' />?"; // Your Auth Token from


        public function getSid()


            return $sid;



        public function getToken()


            return $token;



	public function actionSendsms()




        public function actionReceivesms()





At this point, it would load Services/Twilio.php but would throw an error saying that Services_Twilio_Resource.php could not be found.

I tracked through the twilio library and found that the underscores needed to be replaced with / so it could read the file at twilio/Services/Twilio/Resource.php so i got it working after I inserting the following line above line 427 in yii/framework/YiiBase.php.

$className = str_replace(’_’, ‘/’, $className);

Its obviously not a good idea to be customising the framework files to make 3rd party extensions work so if someone can tell me how it should be done correctly it would be greatly appreciated.

The insertion of the line hasnt harmed the project, everything works perfectly so happy with the result, just not overly happy about having to hack the YiiBase.php file to do make it work.


Greg Johncock

Yii’s autoloader sometimes doesn’t play nice with other autoloaders but there’s an easy workaround to make sure that autoloaders will be called in the right order:

spl_autoload_unregister(array('YiiBase', 'autoload'));

require_once 'Services/Twilio.php';

spl_autoload_register(array('YiiBase', 'autoload'));


Thank you so much.


Greg J

Thank you very much.

So much support for YII from YII developer