Flex with AMFPHP

4,189 views

Published on

Using AMFPHP with Flex 3 to build a CRUD Application

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,189
On SlideShare
0
From Embeds
0
Number of Embeds
821
Actions
Shares
0
Downloads
52
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Flex with AMFPHP

  1. 1. Using AMFPHP with Flex 3 to build a CRUD Application By- Shreyas Tonse Final Year B Tech Student @ NIT-K, Surathkal
  2. 2. Why PHP? <ul><li>Easy to learn and get working (I use WAMP) </li></ul><ul><li>Designed for the Web </li></ul><ul><li>Open Source – Collaborative development </li></ul><ul><li>Lots of open source code & samples </li></ul><ul><li>Popular with the student community </li></ul>
  3. 3. What is AMFPHP? <ul><li>AMF (Action Messaging Format) </li></ul><ul><li>Uses a binary format for serialization </li></ul><ul><li>AMFPHP is a PHP open source library </li></ul><ul><li>Allows PHP Classes to talk to Flex </li></ul>
  4. 4. Why AMFPHP? <ul><li>Faster than any other means of communication </li></ul><ul><li>Allows Flex to send and receive AS strongly typed objects </li></ul>
  5. 5. Setting it up <ul><li>http://sourceforge.net/projects/amfphp/files/#files </li></ul><ul><li>Paste in into your web root </li></ul><ul><li>gateway.php to verify clean install </li></ul>
  6. 6. Writing a Service <ul><li>Use of Object Oriented PHP </li></ul><ul><li>CRUD => use of getters and setters </li></ul><ul><li>Can be used to return a single value, key value pairs </li></ul><ul><li>Return Objects </li></ul>
  7. 7. Testing the Service <ul><li>AMFPHP Browser </li></ul><ul><li>Make test calls </li></ul><ul><li>Gives elaborate statistical info </li></ul>
  8. 8. Using the Service in Flex <ul><li>The RemoteObject: </li></ul><ul><li>  </li></ul><ul><li><mx:RemoteObject id=“yourRemoteObject&quot; source=&quot; yourAMFPHPClassName.ThePHPFile &quot; destination=&quot;amfphp&quot; showBusyCursor=&quot;true&quot;> </li></ul><ul><li>    <mx:method name=&quot; theFunctionYouWantToCall &quot; result=&quot;myFunctionResultHandler(event)&quot; fault=&quot;myFunctionFaultHandler(event)&quot;/> </li></ul><ul><li></mx:RemoteObject> </li></ul>
  9. 9. Using the Service in Flex <ul><li>1. yourAMFPHPClassName is the name of the folder in amfphp/services </li></ul><ul><li>2. ThePHPFile is the PHP class file. </li></ul><ul><li>3. You need the <mx:method name=&quot;...&quot; .../> to define the function in the PHP class you want  to call, theFunctionYouWantToCall in this case </li></ul>
  10. 10. Using the AS Handlers <ul><li>private function myFunctionResultHandler(event:ResultEvent):void </li></ul><ul><li>{ </li></ul><ul><li>var PHPResult:String=String(event.result); </li></ul><ul><li>Alert.show(PHPResult); //will show what the PHP class returned </li></ul><ul><li>} </li></ul><ul><li>This means the PHP function has a return statement like this: </li></ul><ul><li>return $value </li></ul><ul><li>OR </li></ul><ul><li>return &quot;Test&quot;; </li></ul>
  11. 11. Using the AS Handlers <ul><li>private function myFunctionResultHandler(event:ResultEvent):void </li></ul><ul><li>{ </li></ul><ul><li>Alert.show(&quot;Name: &quot;+event.result.name); </li></ul><ul><li>Alert.show(&quot;Age: &quot;+event.result.age); </li></ul><ul><li>} </li></ul><ul><li>This means the PHP function has a return statement like this: </li></ul><ul><li>$returnValue=array(); </li></ul><ul><li>$returnValue['name']=“shreyas”; </li></ul><ul><li>$returnValue['age']=$age; </li></ul><ul><li>return $returnValue; </li></ul>
  12. 12. Mapping Objects <ul><li>Map Server Side VO to and from an ActionScript VO </li></ul><ul><li>Done by adding RemoteClass Meta data to your Class definition </li></ul><ul><li>Return an array of objects from AMF </li></ul>
  13. 13. Alternatives to AMFPHP WebORB for PHP – Exists for other technologies too Zend Framework - The popular PHP framework, now supports AMF SabreAMF – A Google code project which is BSD licensed.
  14. 14. Thank You <ul><li>All resources will be put up on: </li></ul><ul><li>http://flex.tekyt.info </li></ul><ul><li>Will post this tutorial, and queries may be asked as comments </li></ul><ul><li>Twitter: @tusay </li></ul><ul><li>E-mail: shreyastonse@gmail.com </li></ul>

×