New CakePHP Twilio Datasource from Aaron Reisman

June 09, 2010
Written by
John Sheehan
Contributor
Opinions expressed by Twilio contributors are their own

This post is part of Twilio’s archive and may contain outdated information. We’re always building something new, so be sure to check out our latest posts for the most up-to-date insights.

Twilio Bug Logo

Cakephp_logo
Aaron Reisman is a Media Specialist and Founder of Life is Content.
While working on some Twilio projects Aaron
developed a new CakePHP Datasource for accessing the Twilio API via standard model functions. The source code is freely
available on GitHub
. Let’s take a look at an example of how it works.

You’ll need PHP 5.x and CakePHP 1.3.x to use the datasource. Once you have that setup, installation is three easy steps:

  1. Download and add the files to a new CakePHP Project.
  2. Edit the database file and use your credentials.
  3. Modify the texts controller to your needs.

Once configured, a sample controller might look like this:

<?php
class TextsController extends AppController {
function index(){
// Will use the username defined in the $twitter as shown above:
$texts = $this->Text->find('all');
// Create a new text (sends an SMS message)
//$texts = $this->Text->save(array('To' => 4157175170, 'From' => 4152360978, 'Body' => 'This is an update'));
// Finds texts by another username
//$conditions= array('AccountSid' => 'AccountSid');
//$otherTexts = $this->Text->find('all', compact('conditions'));
debug($texts);
}
}
?>

If you use CakePHP, the Twilio Datasource can simplify working with the Twilio API. Head on
over to GitHub
, download it and give it a try in your apps!