O'Reilly logo

Creating Mobile Apps with Sencha Touch 2 by Bryan P. Johnson, John Earl Clark

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The API and the database

To begin with, we need to replace our flat PHP file with some new code. This code will have three basic tasks:

  • Decide what kind of request is coming in
  • Contact the database and make the appropriate request
  • Format the data to be returned to the Sencha Touch application

    Note

    Please note that from this point on, we are looking at PHP code. While some of it looks similar to JavaScript, this code is completely separate from both JavaScript and Sencha Touch.

These three basic functions will hold true no matter what language your API is written in, though the implementation will vary. In PHP our first task would look something like this:

include_once 'dbSetup.inc'; switch ($_SERVER['REQUEST_METHOD']) { case "GET": doGet(); break; case ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required