[EXTENSION] Yii Zend AMF module

Hello,

I have published a yii module that makes it very easy to communicate with Flash/Flex applications.

You can download it on Github.

The module is standalone, Zend AMF is included, if it is outdated you can update it following the instructions.

Instructions how to use it:

The module amfGateway permits anyone to have a very easily configurable RPC with Flash and Flex.

[size="4"]Setting up and usage[/size]

To use the module follow these steps:

Make sure you have a modules folder in your protected folder of your Yii application. If not create it.


Inside the modules directory copy the modules/amfGateway folder provided by this repository.


Now you have to enable the module in your Yii application. Open the file protected/config/main.php and in the modules section add

'modules' => array(

  'amfGateway' => array(

    'servicesDirAlias' => 'application.services.amf',

    'production' => TRUE,

   )

),

Now your gateway for AMF is found at http://yiiurl?r=amfGateway. The classes and methods that are exposed to Flash/Flex are found in the application.services.amf directory which essentially is protected/services/amf. You can find an example in the services/amf/TestService.php file that is provided.

If you have any problem while setting it up and you want to see more error messages, change the ‘production’ parameter seen above to FALSE.

Zend AMF is located in the vendors/ folder inside the module folder. If it is not up-to-date can be easily updated by downloading Zend AMF from http://framework.zend.com/download/amf and then extracting the Zend folder directly into the Zend folder.

[size="4"]Demo[/size]

There is a flash example in the folder flash_demo. To make it work make sure you setup the module as described above. Then copy the services folder in the yii protected/ folder. After that go to amftest.as and change the following line


var gateway:String = "http://amftestapp/index.php?r=amfGateway";

to make sure it points to the right URL according to your computer. You can now run amftest.fla and see in the console the results.

Hi Vassilis,

I installed it and run your sample: it works great!

Since my environment runs csrf validation, I had to disable it for the amfGateway.

I based upon this thread.

I made this customizations:

  1. Extended my own CHttpRequest (created [color="#FF8C00"]/components/FlkHttpRequest.php[/color]):



class FlkHttpRequest extends CHttpRequest

{

	public $noCsrfValidationRoutes=array();


	protected function normalizeRequest()

	{

		parent::normalizeRequest();

		

		if($this->enableCsrfValidation)

		{

			$currentRoute=Yii::app()->getUrlManager()->parseUrl($this);

			foreach($this->noCsrfValidationRoutes as $route)

			{

				if(strpos($currentRoute,$route)===0)

					Yii::app()->detachEventHandler('onBeginRequest',array($this,'validateCsrfToken'));

			}

		}

	}	

}



  1. Configured it in [color="#FFA500"]/config/main.php[/color]:



'components'=>array(

	...

        ...,

        'request'=>array(

        	'class'=>'FlkHttpRequest',

        	'enableCsrfValidation'=>true,

        	'noCsrfValidationRoutes'=>array('amfGateway'),

	),

),



This worked fine. :)

Thank you for this great extension!

Bye,

Andrea

Thank you, and thank you for sharing the csrf customization, very useful!

Can I add it to the Readme.md of the extension with your username

and with reference to this topic?

Surely you can :)

Bye,

Andrea

Hi Vassilis,

how are you?

I’m working with the module and it’s great :)

However I can’t make it work trying to access some services I put in some subdirectories of the servicesDirAlias directory.

Here is my environment:

servicesDirAlias:


protected.services.amf

main service location:


/protected/services/amf/Main.php

subdirectory located service location:


/protected/services/amf/apps/pub/Pub.php

Here is how I’m calling the services’ mirror($params) method from the flash client:

Main service (OK):




nc.call("Main.mirror", new Responder(onResult, onFault), { name:"Andy", age:40 } );



Pub service (ERROR):




nc.call("apps.pub.Pub.mirror", new Responder(onResult, onFault), { name:"Andy", age:40 } );



The Main works fine.

The Pub answers this:

I suspect this is more a ZendAmf issue than yours extension actually…what about this?

Shouldn’t ZendAmf manage to find the /protected/services/amf/apps/pub/Pub.php class, starting from the apps.pub.Pub path by itself?

Why does it transform apps.pub.Pub in apps_pub_Pub instead of turning it into the correct class path?

Is there any place where can I configure this?

Or am I missing something?

I can overcome this by adding some $server->addDirectory() calls to your AmfController class, but I’d rather not modify it an be able to use point formatted paths from as3…

Any idea of how to manage it?

Thank you a nd goodbye,

Andrea

Hi,

Right now, there is no clean way to do it, but I’m working on it.

I will let you know.

-Vassilis

Ok, no problem :)

Thank you for your quick answer.

Bye,

Andrea

hi,

I have integrated this module, When I types the URL a file index.php get downloaded, inside that a content Zend Amf Endpoint is written in that. Please help me…