How to create Magento AMF server extension

Featured Image

I have been working on a project, in my own time, that involves Flex – Magento communication. I decided to test Adobe’s AMF format. In this article I will show you how easy is to create AMF server as an extension in Magento.

So, where to we start?

The idea is to have special Url which will act as AMF endpoint. Since Magento is built on top of Zend, this is extremely easy to do.

For your module to act as a basic AMF server you need only 3 files. MyCompany_MyModule.xml that goes under the /app/etc/modules/ folder. Then IndexController.php that goes under the /app/code/local/MyCompany/MyModule/controllers/IndexController.php. And last but not least the config.xml file that goes under the /app/code/local/MyCompany/MyModule/etc/ folder.

I will not go into the details and show you the full content of each of those files. Important thing is to focus on IndexController.php and config.xml files. Inside your IndexController.php file you will actualy hold the code for your AMF server (Zend_Amf).

Here is an example of indexAction from my IndexController.php file:

...
public function indexAction()
{   
	//Create AMF server instance     
	$server = new Zend_Amf_Server();
 
	//setProduction(false): return exception info
	$server->setProduction(false);
 
	$server->setClass($class, $class);
 
	//$server->setClassMap("SomeTypedObjectVO", "MyCompany_MyModule_Model_SomeTypedObjectVO");
	$server->setClassMap($className, $class);
 
	//Run the AMF server
	echo $server->handle();
 
	//Just in case so that Magento does not pass anything beyond this point
	die;
}
...

The above example is the simplest form of Zend AMF server i can think of, but it should be enough to get your AMF server responsive to AMF requests.

And to make all of this accessible via Url, we need to add entry to congig.xml file. Below is the partial example of my config.xml file.

...
	<frontend>
		<routers>
			<mymodule>
				<use>standard</use>
				<args>
				<module>MyCompany_MyModule</module>
				<frontname>myamfserver</frontname>
			</args>
			</mymodule>
		</routers>
	</frontend>  
...

Above piece of code sets access to AMF server on Url like http://server/store/index.php/myamfserver.

Thats it.


4 comments

  1. Hi Branko,

    I’ve been waiting so long for the release of the Matsiya AMF API for Magento without getting news.

    Have you ever planned about developing an open source AMF API for Magento? If yes, It would be great to participate 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.