Sencha Touch 2 and amfPHP2

Posted by
|

Mathieu Decoene  @Coenego here shares some insights on using Sencha Touch 2 with amfPHP 2

For those who don’t know Sencha Touch: it’s a javascript framework for mobile (based on Sencha
Ext).

It’s always a bit trial and error when new updates are released; new methods, deprecated stuff… I’m
talking about Sencha Touch 2 and amfPHP 2 in this case.

Since we’re talking about mobile apps, Ajax-requests are basically used to receive or send our
data (because we want it to run behind the screens). So, amfPHP is a perfect partner for
communication between Sencha Touch (or any other client framework) and the services.
But some things have changed since boths v1’s… For example: You don’t have to specify your service and
method name any longer in the url-property (to which the request is sent) of the Ajax-request. Now
you have to add both names as a property value together with the other parameters.
Examples of usage:

consider this amfPHP service:


<!--?php class MyService{ function myMethod($data){ // do something with property1 } } ?-->

To call it from Sencha Touch when running it in amfPHP v1, do the following:


var myParams = {
property1: ‘value1’,
property2: ‘value2’
};
Ext.Ajax.request({
method: 'POST',
url: ‘http://www.yoururl.com/amfphp/json.php/MyService.myMethod’,
params: myParams
});

?>

To call it from Sencha Touch when running it in amfPHP v2, do the following:

var myParams = {
serviceName: 'MyService',
methodName: 'myMethod',
parameters: [
{'dataroot': [‘value1’,’value2’]}
]
};

Ext.Ajax.request({
method: 'POST',
url: ‘http://www.yoururl.com/amfphp/?contentType=application/json’,
params: JSON.stringify(myParams);
});

Comments

  1. lexa

    25 avr 12

    Excellent article
    Very promising method for JS/PHP app for mobiles
    At last some people use amfPHP with JS on the client side

  2. ariels

    25 avr 12

    they’ve been doing it for a long time, it’s just that most people don’t know about it yet. This post should help raise awareness

  3. ragav

    16 mai 12

    Good post, I have few doubts. How can I have different classes in different folders as in amfphp1.9? And please provide some standard coding samples.

  4. ariels

    16 mai 12

    in your config you provide several service folders.

Comments are closed

Événements à venir / Upcoming Events

  1. Atelier #1/2 Intelligence Artificielle avec 0 A.D.

    13 avril @ 19:00 - 21:00
  2. Atelier Marketing : Vendre grâce au Web

    16 avril @ 19:00 - 21:00
  3. Atelier #2/2 Intelligence Artificielle avec 0 A.D.

    20 avril @ 19:00 - 21:00
  4. Haxetelier #10 : Haxe-Cordova

    27 avril @ 19:00 - 21:00

WWX2015 crowdfunding campaign

Abonnez-vous à la newsletter

Follow Silex Labs on Twitter

Silex Labs community Tweets

Facebook page