[eluser]Unknown[/eluser]
For more information and source download, check: <br />http://code.google.com/p/zendamf-codeigniter <br />
How to integrate ZendAMF in Codeigniter 2.0
In
application/libraries folder make a .php file called: <br />
zend.php and paste in the following code: <br />
Code:
<?php if( !defined('BASEPATH')) exit('No direct script access allowed');
class Zend {
public function __construct() {
ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.APPPATH.'libraries/');
require('Zend/Loader/Autoloader.php');
spl_autoload_register(array('Zend_Loader_Autoloader','autoload'));
}
}
Extract AMF Zend Framework folder to
application/libraries. The AMF Zend Framework is available at: <br />http://framework.zend.com/download/am
In
application/controllersmake a folder called:
amf. In this folder make a .php file called:
gateway.php and paste in the following code:
Code:
<?php
class Gateway extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('zend');
//root_folder + application + controllers + amf + services
define('SERVICES_FOLDER', APPPATH.'controllers/amf/services/');
}
public function index()
{
$server = new Zend_Amf_Server();
$server->addDirectory(SERVICES_FOLDER);
echo $server->handle();
}
}
?>
Finally, you should see the following folder-file structure:
Code:
--[application]
----[controllers]
------[amf]
--------[services] (folder where you put all your services)
------gateway.php
----[libraries]
----[Zend](zend amf framework package)
----zend.php
Extending your services with CI_Controller
Create a service in your services folder. In my case, I create a service in
application/controllers/amf/services/folder called:
testservice.php. The code for this service: <br />
Code:
<?php
class Testservice extends CI_Controller
{
function __construct()
{
parent::__construct();
}
public function getMessage()
{
return "Hello from " . __Class__; // Hello from Testservice
}
}
?>
Prepare your Flash app to communicate with AMF in Codeigniter 2.0
In your root folder make a folder called:
flash. In this folder create
index.fla.
<br />
Open your index.fla en open your action panel to put in the following code:
Code:
import flash.net.NetConnection;
import flash.net.Responder;
var con:NetConnection = new NetConnection();
// point it to the gateway controller (gateway.php in your application/controllers folder)
var gateway:String = "http://localhost/ZendAMF_integration/index.php/amf/gateway/";
con.connect(gateway);
//call a method named: getMessage in Testservice class.
con.call("Testservice.getMessage", new Responder(onResult, onFault));
function onResult(event:Object):void
{
trace(String(event));
}
function onFault(event:Object):void
{
trace(String(event));
}
When you test your flash application, you should see the following trace message
if done properly)
Code:
Hello from Testservice