Posts tagged amfphp
Calling all PHP Rockstars!
Apr 21st
Hey everyone
We’re looking for some skilled PHP developers to help us innovate with and improve on AMFPHP. If you think you’ve got the goods to help us get this project insanely powerful (but still simple and easy to use), drop us a line!
-
Ariel Sommeria-klein – Project Lead (ariel@amfphp.me)
-
Danny Kopping – Development Lead (danny@amfphp.me)
AMFPHP is back!
Feb 2nd
Today is a wonderful day!
I have teamed up with Ariel Sommeria-klein to revive the legendary AMFPHP project that spawned a whole new dimension of Rich Internet Applications. Together we have brought AMFPHP 1.9 out of beta and made it compatible with PHP 5.3. We have also completely rewritten the AMFPHP service browser and we have several improvements planned for AMFPHP 2.0.
If you would like to help contribute to this great open-source application, please contact us.
AMFPHP Genie v0.2
Dec 13th
AMFPHP Genie (0.2) is a simple tool to help you get shit done using Flex and AMFPHP.
Check out http://dannykopping.co.za/amfphp-genie/ for more information!
Handling multiple remote services with RemoteObject – the easy way!
May 6th
Ok, so you’re developing a Flex application with a bit of server-side integration (using PHP, Java, Ruby, .NET, etc) and your application is getting a little intense; multiple service calls to the server, custom logic for success and failure of said calls and everything in between.
You could use the following syntax for handling mutliple method-calls from a remote script (in this example MyService):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <mx:RemoteObject id="service" destination="amfphp" source="MyService" makeObjectsBindable="true"> <mx:method name="doSomething" result="doSomethingResult(event)" fault="doSomethingFault(event)"/> <mx:method name="doAnotherSomething" result="doAnotherSomethingResult(event)" fault="doAnotherSomethingFault(event)"/> </mx:RemoteObject> <mx:Script> <![CDATA[ private function doSomethingResult(event:ResultEvent):void { // custom logic } private function doSomethingFault(event:FaultEvent):void { // custom logic } private function doAnotherSomethingResult(event:ResultEvent):void { // custom logic } private function doAnotherSomethingFault(event:FaultEvent):void { // custom logic } ]]> </mx:Script> |
I dunno about you, but to have to define special tags in MXML for each bloody method in your script is too much effort (and can leave you with some nasty/tricky bugs if you forget to add a new tag after adding a new method in your server-side script!). I used the following mechanism in my post about integrating CodeIgniter, Flex and PHP if i remember correctly… Give me a break… I was too lazy to check (it’s midnight and i’m sleepless).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <mx:RemoteObject id="service" destination="amfphp" source="MyService" makeObjectsBindable="true" result="resultHandler(event)" fault="faultHandler(event)"/> <mx:Script> <![CDATA[ private function resultHandler(event:ResultEvent):void { var message:RemotingMessage = event.token.message as RemotingMessage; switch(message.operation) { case "doSomething": // custom logic break; case "doAnotherSomething": // custom logic break; default: trace("Shit... Missed this one... " + message.operation); break; } } private function faultHandler(event:FaultEvent):void { var message:RemotingMessage = event.token.message as RemotingMessage; switch(message.operation) { case "doSomething": // custom logic break; case "doAnotherSomething": // custom logic break; default: trace("Shit... Missed this one... " + message.operation); break; } } ]]> </mx:Script> |
Seems much easier, doesn’t it? Essentially all you’re doing is examining the event parameter of the ResultEvent or FaultEvent, finding which method was just called and acting accordingly… This will work with any number of method calls, from any number of different RemoteObjects. You can point them all to the same handlers!
If you guys have any alternative ways of doing this, let me know!
Making your constructors more useful
Mar 30th
The constructor function in Object-Oriented languages is an incredibly useful mechanism to use, and we’ve all used them for a wide variety of solutions.
When i use PHP with Flex, i like taking advantage of AMFPHP’s amazingly nifty feature of being able to send whole objects as binary data to and from the server. This can be vastly useful because you could send a whole object from Flex as an ActionScript class and PHP will receive it and use it as the same class! Here’s a practical example:
You are making an application to control a university’s student details. One logical step would be to go and create a Student class in ActionScript 3.0:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package { public class Student { public var ID:uint; public var firstName:String; public var surname:String; public var age:uint; public var accountPaid:Boolean; public function Student() { } } } |
Now, if you’re using AMFPHP, it’d be a complete ball-ache to have to send the Student class like this (say you were inserting a student into the database):
var student:Student = new Student(); student.firstName = "Jacob"; student.surname = "Zuma"; student.age = 67; student.accountPaid = false; service.addStudent(student.firstName, student.surname, student.age, student.accountPaid);
Wouldn’t it be so much easier to simply do this:
service.addStudent(student);
…and receive the object in PHP, and serialize it into this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php class Student { public $ID; public $firstName; public $surname; public $age; public $accountPaid; public function __construct() { } } ?> |
Well, it’s possible! I covered this is some detail in one of my previous tutorials, and Flex-to-PHP remoting is not in the scope of this particular post. The focus of this post, however, is to give you a couple of tips as to making your constructors more intelligent in the realm of Flex remoting. My two main areas of web development are ActionScript 3.0 and PHP5, but you can easily apply the same logic that follows to all other Object-Oriented languages.
Below is the improvement on my earlier Student class, with the more remoting-friendly constructor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package { import flash.utils.describeType; public class Student { public var ID:uint; public var firstName:String; public var surname:String; public var age:uint; public var accountPaid:Boolean; public function Student(values:Object=null) { if(values) { var props:XMLList = describeType(this)..accessor; for each(var prop:XML in props) this[prop.@name] = values[prop.@name]; } } } } |
* More information on the describeType function here.
And the PHP equivalent:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <?php class Student { public $ID; public $firstName; public $surname; public $age; public $accountPaid; public function __construct($properties=null) { if($properties) { $properties = new ArrayObject($properties); foreach(get_object_vars($properties) as $prop => $value) $this->$prop = $value; } } } ?> |
Now, you can easily pass an object (with no type) to either of these constructors, and they will automatically transform that object into a strongly typed, meaningful and above all else – easy to work with – variable.
Integrating Flex, AMFPHP and CodeIgniter (also including Value-Objects)
Jan 5th
Server.Acknowledge.Failed – another AMFPHP ballache
Nov 3rd
While working on a project today, i encountered a serious ballache in the form of this:
mx.rpc.Fault (@14f27331)
[inherited]
faultCode “Server.Acknowledge.Failed”
faultDetail “Was expecting message ’93EDDF20-516F-2C3F-AA63-619BAB9DA793′ but received ”.”
faultString “Didn’t receive an acknowledgement of message”
rootCause null
AMFPHP, for all it’s wonder and usefulness, doesn’t document its errors very well. Very irritating. After much digging, i found that the solution to this isn’t actually anything to do with the AMFPHP framework, nor with Flex! It’s stupid little error in PHP… Make sure that you aren’t trying to return an array or object in PHP that has an undefined index or property. I slapped my forehead when i realised the error of my ways.
Sigh.
Integrating CodeIgniter with AMFPHP
Nov 2nd
A while back i spent an evening hacking away at the CodeIgniter source code. I was desperate to use it as a library, as opposed to a framework. I don’t use PHP with HTML. I did for a little bit, but personally i found that HTML and CSS were the biggest load of shit languages ever to plague my existence! Sorry. Once i was introduced to Flash and Flex, i said “to hell with HTML and it’s ugly sister CSS! I’m becoming a banner-maker!”. Not quite… i’ve never made a banner – even though that’s like totally the whole point of Flash, dude… (insert stupid programmer comments here).
Ahem. Back to the point. So when i started writing Flex apps and using AMFPHP for my remoting, i desperately wanted a nice concise, easy-to-use, well documented library. Enter CodeIgniter by Rick Ellis. Although CI is actually a MVC framework for PHP, i decided i was going to turn it into a library! (and what a ballache that was).
Below is the massive, complex, obfuscated script I wrote to turn it into a library. Notice how the script seems to drip with programming excellence:
<?php if (!defined('BASEPATH')) define ("BASEPATH", "../CodeIgniter/system/"); if (!defined('APPPATH')) define ("APPPATH", "../CodeIgniter/system/application/"); if (!defined ("EXT")) define ("EXT", ".php"); require_once (BASEPATH."codeigniter/Base5.php"); require_once (BASEPATH."libraries/Controller.php"); require_once (BASEPATH."codeigniter/Common.php"); ?>
Crazy huh? Haha. Essentially, all this script does is fuck with some of the framework architecture and allow the package to be required in PHP. See the usage below:
<?php
require_once("CodeIgniter.php"); // the path to your CodeIgniter.php script as described above
class AMFPHP_CI_Integration { function __construct() // PHP constructor { parent::Controller(); // Extend the functionality of the CI Controller class } }
?>
And that’s it! Flimsy and hackerish, i know, but hey… It works
Any queries or suggestions are most welcome!
