Home > Flash Platform, Zend_Amf > Bootstrap file for Zend Amf

Bootstrap file for Zend Amf

November 4th, 2008

There seems to be lots of questions about the best way to setup your bootstrap/endpoint/index.php file in order to work with Zend Amf. The idea of leveraging the Zend MVC framework to route to your server endpoint is a common question but personally seems like a bad idea. Although it may seem convenient it does not provide any MVC integration and second will slow down the response time of your service greatly.

I typically have something like the following structure:

public/
  .htaccess
  index.php
  xmlrpc.php
  jsonrpc.php
  amf.php

In my .htaccess, I have the following:

php_value date.timezone "UTC"
php_value short_open_tag 1
php_value error_reporting 8191
php_flag  display_errors Off
php_flag  display_startup_errors Off

# Rewrite Rules
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^/?xmlrpc  xmlrpc.php  [NC,L]
RewriteRule ^/?jsonrpc jsonrpc.php [NC,L]
RewriteRule ^/?amf     amf.php     [NC,L]
RewriteRule ^.*$       index.php   [NC,L]

Then, in my amf.php, I’d have the following:

setClass(...); // etc...
echo $server->handle();

The rewrite rules allow you to go directly to the given file, and then each file sets up the include_path, autoloading, and the server.

Flash Platform, Zend_Amf

  1. November 5th, 2008 at 15:39 | #1

    Where the heck was that last weekend at 3 in the morning? Seriously, Thanks for posting this. So this gives us access to the framework via the index and the other server through their respective url right? Would this be the recommended approach for other Zend Servers also?

  2. November 5th, 2008 at 15:50 | #2

    Yes this was recommended to me by Matthew Weier O’Phinney and I just assume that he speaks the truth.

  3. Adnan Doric
    November 6th, 2008 at 11:04 | #3

    Hello Wade,

    I have a problem with class mapping. I try to use the remoting example (zend-php-samples) with ContactDAO class as following :

    bootstrapamf.php :
    $server = new Zend_Amf_Server();
    $server->setClass( “ContactDAO” );
    $server->setClassMap( “ContactDTO”, “Contact” );

    Everything works fine, but in ContactDAO, function getContacts() returns an array of contacts but in Flex they are not typed.

    ContactDTO.as :
    [RemoteClass(alias="Contact")]
    [Bindable]
    public class ContactDTO
    {
    public var id : int;
    public var firstname : String;
    public var lastname : String;
    public var email : String;
    public var mobile : String;
    }

    Any help on this please ?

  4. Stefan Schmalhaus
    November 25th, 2008 at 09:19 | #4

    How about using Zend_Db::factory() inside the bootstrap file?

  5. November 26th, 2008 at 12:22 | #5

    I blogged on utilizing Zend_Db and Zend_Config for Zend_Amf:
    http://blog.log2e.com/2008/11/26/whats-in-the-zend-framework-for-the-flashflex-developer/

  6. December 13th, 2008 at 20:00 | #6

    In case you want to build a hybrid application with both Flex and HTML interfaces, it’s not a good idea to put all Zend AMF-related code inside the bootstrap file. For more flexibility, I suggest to set up the Zend AMF server inside a regular Zend controller that can be used as AMF gateway:

    http://blog.log2e.com/2008/12/14/utilizing-the-zend-amf-server-inside-a-zend-controller/

  7. December 17th, 2008 at 15:00 | #7

    @Stefan Schmalhaus What is the benefit for a hybrid application in using the controller to handle the amf request?

  8. January 25th, 2009 at 14:11 | #8

    @Stefan Schmalhaus:
    i think your solution is quite clever. i’ve tested it and it just works fine. but then i’ve read wades comment, which insecured me a little bit …

    @wadearno:
    i understand you (rhetorical) question cause it’s obvious, that the indirect call “will slow down the response time of your service”. but for me as a newbee to zend_amf and zend framework the question comes: why zend_amf is a part of zend framework, if i should not use the mvc integration of the zend framework?

    please don’t understand me wrong. i realy love zend_amf cause it’s much more flexible than amfphp. but it makes me feel uncomfortable if zend_amf has to be treated different than the rest of the framework …

    best regards
    jan viehweger

  9. Renato Bejarano
    February 2nd, 2009 at 22:39 | #9

    Hi Wade, I am sorry to tell you that I totally agree with Jan Viehweger. I have been trying effortless to integrate the AMF server with the mvc integration, either setting it up in the bootstrap file or a Stefan suggested in a controller. I don’t know how it was done before, but it seemed to me with the newest version I downloaded I had some problems. I couldn’t use echo (server->handle()) before dispatching the controller, because of the HTTP header being different than text/html. And whenever I just put server->handle(), without echo after dispatching the controller I got the page rendered but I didn’t get responses from the amf server. It was a pain hoping to find a complete sample integrating an amf server with the mvc model in the zend framework. (Which is basically the heart of the zend framework). And of course I couldn’t find, because what you expect that would be normal, actually doesn’t work like that. Please warn this in your documentation, and give a technical explanation, so it wouldn’t sound that weir what you are proposing here in this post.

    Thanks

  10. February 9th, 2009 at 10:08 | #10

    @Renato & @jan The good thing about the framework is that there are people with opinions. The bootstrap configuration that I suggested is based on personal preference and feedback from my zend liaison. I don’t believe that this is a right or wrong question but a personal preference. Look at Zend_Amf_Response_Http as that is where the headers are being set. This could be removed but please open a ticket as community feedback so that we can get the community’s opinion on removing the headers from the response.

  1. January 29th, 2010 at 08:58 | #1