2 Replies Latest reply on Jul 17, 2010 3:46 PM by Jens Wegar

    How to setup Data services to use existing zend application

    Jens Wegar Level 1

      The application I'm working on is going to have views created both in Flex and in PHP. Thus, we want to setup the Zend framework so that it can be used for the PHP part of the application and to display views in the browser. We want to setup the AMF gateway so that it's a service provided through a controller in Zend and with the actual service classes hidden from public view in the application folder, and not like the default now seems to assume that you create a folder in your public webroot where the endpoint and all service classes live.

       

      So the structure we are after is

       

      Zend_AMF endpoint at http://example.com/services/amf

       

      Zend folder structure:

       

      application/controllers/ServiceController.php    // the controller that handles all incoming requests, so acts as the gateway.phpI assume

      application/services/amf/    // contains the actual service classes, e.g. Users.php, Products.php

       

      public/swf/    // will contain the actual .swf files for the Flex application

       

      the /public/ folder is set to the webroot with /application/ outside the webroot as per the Zend framework recommendations.

       

      I would like to use the Data service introspection to generate the Flex code for the services, however the introspection afaik requires the services to be in the /public/ folder or a subfolder there. So how can I make introspection work for a service that lives in /application/services/amf and is accessed through http://example.com/services/amf ?

       

      Suggestions? links to tutorials?

        • 1. Re: How to setup Data services to use existing zend application
          Mayank (Adobe) Adobe Employee

          Php classes outside webroot are currently not supported by the data introspector. You can however, use the sample generation to get an idea of how to access the php service from your flex application and then handcode a custom service and gateway.php file.

           

          -mayank

          • 2. Re: How to setup Data services to use existing zend application
            Jens Wegar Level 1

            Yes, well hopefully this will be supported in the future. In the mean  time, I've noticed that it's only actually when creating the service  and the API for it that you need to have the class inside the web root.  In order to configure the return types and input types you don't need to  go through the standard gateway.php anymore. So, although not ideal,  here's how I do it right now:

             

            1. I have set up m zend  framework as described in my first post, with my AMF service gateway being a Zend controller and not the gateway.php

            2. I create the service class with the API I need inside the application/services/amf folder. If the service needs to connect to the database then I create a Zend Db Model using the zf command line tool (as per Zend framework practices) and then hook my service class to use that. Which basically means that my service classes are very slim and simple.

            3. When I created the Flex project I created a dummy service using the sample  php, which has set up Flash builder with the default gateway and so on

            4. Once I've created my service class, I copy the file to the default location where Flash Builder wants to create my services. I then strip out any implementing code from the copied file, leaving only the public API and empty methods.

            5. I then create a new service in Flash builder, point it to the stubb class in the default location and let the introspection discover the public api. This will of course mean that all input values and return values are generic objects.

            6. After this is done I delete the stubb class. In the created AS service class I override the service endpoint so that it points to my real gateway controller within the zend framework.

            7. After this is done I can configure the return types and input types using auto discovering. It will connect to the real gateway and ignore the default gateway and thus I can develop against the real endpoint and don't need to create my service classes within the public location of the Zend folder structure.

             

            It's a bit of a workaround for sure, but since I don't create new services that often and I can have Flash builder update my return types etc. automatically this way, I figure it's worth the extra steps. Still, I would hope that in the future Flash builder will support having the introspection happen on a location outside the projects own web root.