CakeSWXPHP

This article is also available in the following languages:
By wouter
SWX is the native data format for Flash. It uses SWF files to store and exchange data. It is also an implementation of an RPC gateway (currently in PHP), tools (a data analyzer/debugger and a service explorer), various APIs (Flickr, Twitter, etc.), and an ActionScript library that make creating data driven Flash and Flash Lite applications a piece of cake.
I based this code on the cakeamfphp project. The SWX project by Aral Balkan also contains amfphp 1.9. Looking at the code from cakeamfphp, I was able to get SWX running and call the cake controllers as remoting services.

Download the latest version at: http://blog.aboutme.be/cakeswxphp
Just copy/past in your cake directory! Gateway locations are:

swx.php (SWX)
amf.php (AMFPHP)
json.php (JSON)

You can test your methods, using the SWX service explorer. Point your browser to the "explorer/" directory, and you will see your cake controllers + methods as remoting services!

Currently it uses an adjusted version of SWX, based on SWX 1.0. I will try to update it to future versions of SWX when I get the time...

More info about SWX at:

http://www.swxformat.org/ http://www.aralbalkan.com/ (Aral Balkan, SWX author)

Enjoy!

Comments

  • Posted 11/05/09 04:36:59 AM
    Hi I would really like to use this if I can get it working and I will post a tutorial on the flash side and on the cake php side but I cant see why I'm getting the following error, I'm hoping you can help. I would like to use it with cake. It seems to work fine stand alone.

    http://groups.google.com/group/swx-format/t/6581b613a398dd07?hl=en
    thanks for your input greatly appreciated.
    calvin
  • Posted 10/28/09 04:43:17 AM
    I am trying with the beta of 1.3 will try later using 1.2 (yes same issue) but I get a connection and charles says this

    description String The class {DiscoveryService} could not be found under the class path {W:\www\cake_1.3-dev\app\controllers/discovery_service.php}

    would like to know what I do wrong
  • Posted 03/19/09 02:37:15 PM
    It seems that if you send a string value that begins with a number, such as "123abc" to a controller method, by the time it reaches the method, it's value has been shortened to "123". I assume that somewhere along the line, 123abc is being interpreted as a number instead of a string, and the trailing characters are being cut off.

    Anybody seen this?
    • Posted 04/02/09 07:13:31 PM
      It seems that if you send a string value that begins with a number, such as "123abc" to a controller method, by the time it reaches the method, it's value has been shortened to "123". I assume that somewhere along the line, 123abc is being interpreted as a number instead of a string, and the trailing characters are being cut off.

      Anybody seen this?

      Same here. When passing across a session variable which often starts with a number, only the number gets passed along, which makes authenticating a session I nightmare - unless there's an obvious fix.
      Think this is just occurs with the explorer. Running everything from within my own ActionScript seems to pass variables correctly. Have to admit this does cause problems trying to test results though.
  • Posted 01/09/09 08:21:57 AM
    When using SWX Explorer 1.0, I get the following error when calling any function from my controllers:

    TypeError: Error #1009: Kan geen eigenschap of methode benaderen via een verwijzing naar een object dat null is.
    at RawAmfService/readData()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    The functions show up just fine, they are all there and what not. I installed the calculator.php test to check, and it gives this error as well. What is causing it?
  • Posted 01/04/09 10:30:49 AM
    Adam,

    It works fine here... Might be a problem in your php script?
  • Posted 01/04/09 05:04:30 AM
    First of all, thank you for all you hard work on this. Great contribution.

    I am installing the new version that uses SWX 2.0. I have put all the files in their appropriate places. I am able to load up the ServicesBrowser at /amf.php and see my controllers and actions.

    Problem is when I try and run a simple index action I get the following error back:

    faultString = "array_merge() [http://php.net/function.array-merge]: Argument #2 is not an array"

    message = "faultCode:AMFPHP_RUNTIME_ERROR faultString:'array_merge() [http://php.net/function.array-merge]: Argument #2 is not an array' faultDetail:'/opt/local/apache2/htdocs/sales_integration/cake_1.2/cake/libs/controller/controller.php on line 950'"

    Any idea what is going on?
  • Posted 08/11/08 03:16:31 AM
    Craig,

    This is an issue with the current cakephp RC, which has been resolved in the svn version. Download the latest cakephp 1.2 from SVN, and it should work ok :)
  • Posted 07/25/08 07:51:32 PM
    For some reason using the email component doesn't work when using remoting? The same thing happens when i use AMFPHP. It doesn't receive any of the variables that I $this->set in the controller?
    • Posted 03/19/09 02:03:07 PM
      For some reason using the email component doesn't work when using remoting? The same thing happens when i use AMFPHP. It doesn't receive any of the variables that I $this->set in the controller?
      Add this to your controller:

      function beforeFilter() {
      $this->Email->startup($this);
      }
  • Posted 07/13/08 02:02:48 AM
    I updated the branch for 1.2, removing some deprecated code which caused errors in the latest version of cakephp 1.2...

    Download the latest version at http://blog.aboutme.be/cakeswxphp/
  • Posted 05/03/08 05:35:50 PM
    I tried this with the latest nightly of cakephp 1.2 (5/3/2008) and every time that your code calls the function vendor, cake shows a warning (they deprecated the vendor function), I told vendor to shush with the @ thingy and it is now working like a charm!!!
    That is: I changed every ocurrence of "vendor(..." with "@vendor(..."

    What is the swx version included in your code?? the comments say its 1.03 beta but it says 1.0 on the explorer.

    Cheers and thanks again for great work!
  • Posted 04/30/08 08:35:43 AM
    Trying to work my way through the code I'm really desperate to find out how to return the Date datatype through AMF to flex with cakeswxphp.
    AMFPHP itself seems to support it but how do I tell that to cakeswxphp? Any idea?
  • Posted 12/14/07 11:13:24 AM
    Hey guys,

    We ran into the same problem when we moved our cake core up to v1.2. If you turn on debugging and view your gateway pages in your browser, you should see a message about how the loadController() method is deprecated. We just changed:

    loadController(null) to App::import('Controller', 'App'); in
    cake_amf_gateway.php, cake_json_gateway.php, and cake_swx_gateway.php to get our AppController class importing properly.. that fixed it with cake v1.2 for us.

    best,
    jon
    • Posted 05/03/08 02:42:35 PM
      Thanks for sharing this!!! It really looks great!! I am going to use it in a new flash project.
      One quick question: Is updating versions of swx just a matter of downloading swxphp from Aral's website and putting it in /vendors/swx/php???
      Do you want to share guidelines for updating it to the newest version of swx??

      Thanks!
    • Posted 12/18/07 12:47:14 PM
      I updated the cakeswxphp packages. Changes:

      - gateway locations are now amf.php, swx.php and json.php
      - added a branch for cake 1.2 (thanks for the input Jonathan)

      Again, you can download it at http://blog.aboutme.be/cakeswxphp/
  • Posted 11/19/07 01:23:56 PM
    Still can't it to work. I specified all sorts of paths.
    localhost I thought was an issue, I used an IP... no luck.
    /app/webroot/ still no good.

    I don't know what to say. I'm super excited about SWX but this isn't working. I'm using cake version 1.1. something...maybe I have the wrong version?

    Getting some strange error about the call failing:

    faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.BadVersion: : url: 'http://dev.local/triv-swx/app/webroot/amfphp.php'

    Any clues? AMFPHP with CakePHP was easier to setup than this and from reading the SWX site, that shouldn't be the case. Also I want to use SWX and not the AMF...I already have AMFPHP with Cake working, so even using this amfphp gateway is silly to begin with.
    • Posted 11/26/07 10:02:31 AM
      Still can't it to work. I specified all sorts of paths.
      localhost I thought was an issue, I used an IP... no luck.
      /app/webroot/ still no good.

      I don't know what to say. I'm super excited about SWX but this isn't working. I'm using cake version 1.1. something...maybe I have the wrong version?

      Getting some strange error about the call failing:

      faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Connect.Failed error NetConnection.Call.BadVersion: : url: 'http://dev.local/triv-swx/app/webroot/amfphp.php'

      Any clues? AMFPHP with CakePHP was easier to setup than this and from reading the SWX site, that shouldn't be the case. Also I want to use SWX and not the AMF...I already have AMFPHP with Cake working, so even using this amfphp gateway is silly to begin with.

      Hello Tom,

      The path the the amf gateway would be:

      'http://dev.local/triv-swx/app/webroot/cake_amf_gateway.php' 'http://dev.local/triv-swx/app/webroot/amf.php'

      I'm planning to change the path's to the default SWX paths in the next commit, so amf would be amf.php, swx would be swx.php (instead of cake_amf_gateway.php or cake_swx_gateway.php) Been there, done that :-)

      Good luck!
      • Posted 11/27/07 02:51:19 PM
        yea...still have that bad call error... looking forward to a future version, maybe i'll have more luck then.

        maybe there's a server setting i have locally that's not jiving. who knows.
        • Posted 11/28/07 09:20:43 AM
          yea...still have that bad call error... looking forward to a future version, maybe i'll have more luck then.

          maybe there's a server setting i have locally that's not jiving. who knows.

          Tom, maybe the answer is in the php error log? The location of the error might be in there...
  • Posted 11/05/07 08:56:58 AM
    I can't seem to get the SWX gateway to work. I've got the AMF gateway working but the SWX gateway fails. All I did was drop the CakeSWXPHP files into a new cake (1.2.x.x) app.
    • Posted 11/17/07 12:26:33 PM
      I can't seem to get the SWX gateway to work. I've got the AMF gateway working but the SWX gateway fails. All I did was drop the CakeSWXPHP files into a new cake (1.2.x.x) app.
      Brian, currently 1.2.X.X is not supported yet. I'm working on this, expect an update in the near future!
  • Posted 10/11/07 01:49:12 PM
    I ran through your tutorial for setting up a Flash Blog http://blog.aboutme.be/2007/09/30/flash-remoting-with-swx-and-cakephp/#comment-3217 and I got everything set up correct or so I thought. When I call the methods from my swf I get timeouts, when I call them from the Service Explorer I get timeouts...I went through the tutorial step by step (twice to be sure).

    Any idea why this would be happening?

    I have a sample of my problem here http://www.pbjs.com/dev/bizKids/testSWX.html
  • Posted 09/11/07 10:00:09 AM
    I don't know...I'm getting all sorts of errors with the RPC calls and what not when going to the service browser/explorer.

    I would really . REALLY . love some simple "drag these files into a folder and it works" type solution over the time it takes to setup the amfphp, but I'm still on the fence about all this.
    • Posted 09/14/07 11:47:40 PM
      I don't know...I'm getting all sorts of errors with the RPC calls and what not when going to the service browser/explorer.

      I would really . REALLY . love some simple "drag these files into a folder and it works" type solution over the time it takes to setup the amfphp, but I'm still on the fence about all this.

      Tom,
      Make sure you are calling your path to amf correctly. I had to manually change it to http://mydomain.com/app/webroot/cake_amf_gateway.php
  • Posted 08/10/07 07:55:47 AM
    There was a bug in the php4Exception & php5Exception files, which is now fixed. You can find the latest version at http://blog.aboutme.be/cakeswxphp

Comments are closed for articles over a year old