Welcome Guest, Not a member yet? Register   Sign In
ZendAMF integration in Codeigniter 2.0
#1

[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:
&lt;?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:
&lt;?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();
    }
}

?&gt;
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:
&lt;?php
class Testservice extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
    
    public function getMessage()
    {
        return "Hello from " . __Class__; // Hello from Testservice
    }    
    
}
?&gt;

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 messageSadif done properly)
Code:
Hello from Testservice
#2

[eluser]Unknown[/eluser]
Everything seems to be working except for addDirectory.

If I do $server->addFunction('testFunction') and then include the function outside of the gateway class, I can call it just fine.

Am I missing something?
#3

[eluser]ndriana[/eluser]
Error opening URL 'http://localhost/CodeIgniter/index.php/amf/gateway/'
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed
at index_fla::MainTimeline/frame1()

it was an error when I compiled the Flash
#4

[eluser]ndriana[/eluser]
My bad,

The first error was caused by my firewall.
The second error was due to the trailing spaces at the end of the files gateway.php and testservice.php.

Otherwise, it works like a charm
#5

[eluser]pieter dekker[/eluser]
Hi,

I've a question about this library. I've used the amfphp library in combination with codeigniter 1.7.2. And I could use the service just like a regular controller and it was also hooked on a session.
I'm upgrading codeigniter to 2.02, but when I tried using amfphp or zend amf, I couldn't connect to my original session and my already loaded libraries. Is there a solution to this problem?

Best,
Pieter




Theme © iAndrew 2016 - Forum software by © MyBB