Part of the EllisLab Network
   
3 of 3
3
amfphp with CI
Posted: 08 August 2008 01:58 PM   [ Ignore ]   [ # 31 ]  
Summer Student
Total Posts:  10
Joined  07-18-2008

Woop, figured this out myself. I see now from the code that the second parameter passed to the remote method is just stashed in $_POST.

If I change the code in my controller to the following, the function returns that the param is indeed and array.

function func()
    
{
        
global $value;
        
        
// get post
        
$param = $_POST;
        
        
$returnVal = 'param is unknown type';
        if (
is_array($param))
            
$returnVal = "param is array";
        else if (
is_string($param))
            
$returnVal = "param is string";
        else if (
is_numeric($param))
            
$returnVal = "param is numeric";
        else if (
is_null($param))
            
$returnVal = "param is null";
            
            
        
$value = $returnVal; // $value can be any data type. If it's an array, it should be sent back as an array collection.
    
}
Profile
 
 
Posted: 19 August 2008 05:33 AM   [ Ignore ]   [ # 32 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

Hi,

I’m having problems with this.
I followed all the steps, but always get errors.

I’m trying it with AMFPHP 1.9. Is this the version you’re using?
Flash CS3 and CI 1.6.3.

My folder structure is the following:
- index.php
- amfphp/
- system/
Is this correct?

Whenever I go to the Service Browser at http://localhost/amfphp/browser/ and call the execute method with cont/func as the path, I see the error:

(Object)#0
  
message = "faultCode:INVALID_AMF_MESSAGE faultString:'Invalid AMF message' faultDetail:' '"
  
name = "Error"
  
rootCause = (null)

And when I test from Flash, I get the error:

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
    
at amfphp_03_fla::MainTimeline/frame1()

Is there anything else that has to be changed?
Is there anyting I’m missing?

For example, I had to change

require_once('../../../index.php');
// to
require_once('../../index.php');

otherwise I would get an error…


Adding another method (for testing purposes) to the action class, works just fine… (both the Service Browser and testing from Flash)

function test ()
{
return 'hello';
}
Profile
 
 
Posted: 19 August 2008 05:41 AM   [ Ignore ]   [ # 33 ]  
Summer Student
Total Posts:  10
Joined  07-18-2008

I never tested it with the service browser. I got it to work with the HelloWorldExample first.

I would suggest reviewing the steps in the wiki article to make sure you didn’t miss anything. I found I had missed some steps - including setting up the hook correctly.

I also had to change the path to the index file as you did above.

A

Profile
 
 
Posted: 19 August 2008 05:47 AM   [ Ignore ]   [ # 34 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

hi august.gresens,

The problem is that I’ve reviewd it a couple of times… restarted from scratch… but no luck.

You don’t happen to have the files (and folders) from that simple example that I’d just drop here, and compare in order to see what I’m doing wrong, do you?

Thanks

Profile
 
 
Posted: 19 August 2008 06:46 AM   [ Ignore ]   [ # 35 ]  
Summer Student
Total Posts:  10
Joined  07-18-2008

sure, here are my files:

in <web_root>/system/application/config/config.php

/*
|--------------------------------------------------------------------------
| Enable/Disable System Hooks
|--------------------------------------------------------------------------
|
| If you would like to use the "hooks" feature you must enable it by
| setting this variable to TRUE (boolean).  See the user guide for details.
|
*/
$config['enable_hooks'] = TRUE;

 

<web_root>/system/application/config/hooks.php

(NOTE: I remember now there was a problem with this file. I had forgotten to add the closing “?>” php tag at the bottom. This is easy to do because of the way the default file is set up.

<?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files.  Please see the user guide for info:
|
|    http://codeigniter.com/user_guide/general/hooks.html
|
*/


$hook['display_override'] = array(
        
'class'    => 'Amfphp',
        
'function' => 'output',
        
'filename' => 'amfphp.php',
        
'filepath' => 'hooks'
        
);

/* End of file hooks.php */
/* Location: ./system/application/config/hooks.php */
        
?>

<web_root>/system/application/hooks/amfphp.php

<?php
class Amfphp
{
    
var $ci;
    function
output()
    
{
        
if(!defined('AMFPHP'))
        
{
            $this
->ci =& get_instance();
            
$this->ci->output->_display($this->ci->output->get_output());
        
}
    }
}
?>

<web_root>/amfphp/services/ci.php

NOTE: This was not clear in the wiki - it doesn’t give you an exact path to the services file, it just says to create one.

<?php
class ci
{

    
function execute($path, $vars=false)
    
{
        define
('AMFPHP', 1);

         global
$value;        

         if(
$vars AND is_array($vars)){
            
// Convert vars to POST data
            
$_POST = $vars;
        
}  
                          
        $_SERVER[
'PATH_INFO'] = '/'.$path;
        
$_SERVER['QUERY_STRING'] = '/'.$path;
        
$_SERVER['REQUEST_URI'] = '/'.$path;
        
        require_once(
'../../index.php');
        
        return
$value;
        
    
}
    
}
?>

I then call this from flash like so:

(Note: this is not tested code - but has all of the calls I use)

var args:Object = {'arg1':1,'arg2':2};

var
connection:NetConnection = new NetConnection;
var
responder:Responder = new Responder(onResult, onFault);
connection.connect("http://www.your_host.com/amfphp/gateway.php");
connection.call('ci.execute', responder, 'your_controller/your_controller_method', args);

This will populate $_POST with an associative php array.

Hope this helps.

A

Profile
 
 
Posted: 19 August 2008 08:14 AM   [ Ignore ]   [ # 36 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

Hi again, and thank you very much for your time and thorough explanation.

Apart from the closing “?>” which I didn’t have, everything is exactly the same.
This is driving me insane.

The only exception is that I’m using localhost - http://localhost/ - instead of http://www.your_host.com/.
This is the base url in config.php

$config['base_url']    = "http://localhost/";

The ActionScript is the same…

var args:Object = {'arg1':1,'arg2':2};

var
connection:NetConnection = new NetConnection();
var
responder:Responder = new Responder(onResult, onFault);
connection.connect("http://localhost/amfphp/gateway.php");
connection.call('ci.execute', responder, 'cont/func', args);

function
onResult (responds:Object):void
{
    trace
(responds);

    var
t:Array = responds.serverInfo.initialData;
    for(var
i:uint=0; i<t.length; i++)
    
{
        trace
(t[i][0]);
    
}
}

function onFault (responds:Object):void
{
    trace
(responds);
    
    for (var
i in responds)
    
{
        trace
(responds[i]);
    
}
}

Is there anything else… some configuration… some detail… ?

I’ve uploaded all the files here.
They have exactly the same stucture I mentioned previously

- index.php
- amfphp/
-
system/

along with an .fla file.

So, if you could provide an extra pair of eyes, I’d really apreciate it.

Profile
 
 
Posted: 19 August 2008 10:46 AM   [ Ignore ]   [ # 37 ]  
Grad Student
Avatar
Rank
Total Posts:  44
Joined  03-15-2006

If you are not using Charles Proxy, download it NOW. This program will display php errors that result in a non-descriptive, hard to track error in Flex or Flash. If you have a space before or after <?php ?>, Charles will tell you what file to look in.

Most problems occur due to something being output to the “browser”. In your Gateway.php file for Amfphp, setting production server to true may stop some output.

define("PRODUCTION_SERVER", true);

Also try changing this line in your index.php file.

//error_reporting(E_ALL);
    
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

The reason for the following line going up 3 directories is due to my directory structure. I should have mentioned that in the services directory, the action.php file sits in another directory called ci (gateway/services/ci/action.php).

require_once('../../../index.php');

So, if I didn’t stress if enough above, download Charles Proxy. They have a Free trial.

Profile
 
 
Posted: 19 August 2008 12:21 PM   [ Ignore ]   [ # 38 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

Thank you both.
Somehow, it’s working now.

I’ll try to post back when I find out what went wrong at first.

Profile
 
 
Posted: 09 September 2008 01:30 PM   [ Ignore ]   [ # 39 ]  
Grad Student
Avatar
Rank
Total Posts:  38
Joined  08-29-2007

would you mind re-upping your working source code? I am trying to work this integration out as well. With no luck so far. Getting the dreaded message:

Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion at amfphp_03_03_fla::MainTimeline/frame1()

thanks

 Signature 

vevmedia code-igniter things

Profile
 
 
Posted: 10 September 2008 06:19 AM   [ Ignore ]   [ # 40 ]  
Grad Student
Avatar
Rank
Total Posts:  38
Joined  08-29-2007

does anyone have a working example of this that I could sift through?
want to integrate this option (AMF output) in my CMS, Shanti CMS (available for download). Will credit whomever has a working example I can use to start of with
thanks

V

 Signature 

vevmedia code-igniter things

Profile
 
 
Posted: 10 September 2008 08:01 AM   [ Ignore ]   [ # 41 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

hi,

Here are the files.
If you test the Flash Movie, and use the correct url, you’ll see the returned value of “hello”.
This is the value that the method “func” is returning, in the Controller “Cont”.

Instead of a string, you could return numbers, arrays, booleans…

In this controller, you need to grab the parameters that come from Flash using the POST array.
(In this case I’m not sending parameters)

Hope this helps!

Profile
 
 
Posted: 10 September 2008 08:11 AM   [ Ignore ]   [ # 42 ]  
Grad Student
Avatar
Rank
Total Posts:  47
Joined  01-24-2007

And here is an example passing arguments:

The AS:

var myArray:Object = ['world'];

var
connection:NetConnection = new NetConnection();
var
responder:Responder = new Responder(onResult, onFault);
connection.connect("http://localhost/amfphp-ci/amfphp/gateway.php");
connection.call('ci.execute', responder, 'cont/funcWho', myArray);

function
onResult (responds:Object):void
{
    trace
(responds);
}

function onFault (responds:Object):void
{
    trace
(responds);
}

And a new function added to the controller:

function funcWho()
    
{
        
global $value;
        
        
// get post
        
$who = $_POST[0];
        
         
$value = array('hello ' . $who);
    
}
Profile
 
 
Posted: 10 September 2008 10:57 AM   [ Ignore ]   [ # 43 ]  
Lab Assistant
RankRank
Total Posts:  268
Joined  03-12-2007

FYI, Adobe is officially building a library to work with the Zend Framework, so you may want to look there in the future if you need AMF/PHP support.  I think it is still in proposal stage though, so not yet.

Profile
 
 
Posted: 14 September 2008 04:59 PM   [ Ignore ]   [ # 44 ]  
Grad Student
Avatar
Rank
Total Posts:  38
Joined  08-29-2007

Thank you so much. looking through it now, equipping Shanti’s output structure up with AMF.

V.

 Signature 

vevmedia code-igniter things

Profile
 
 
Posted: 04 September 2009 10:19 AM   [ Ignore ]   [ # 45 ]  
Summer Student
Avatar
Total Posts:  3
Joined  08-04-2009

Thanks to everyone working on this!

Definitely some interest in getting CI working with AMF.  I love working with CI but with the nice integration with the FlashBuilder/AMF/Zend stack Zend again gets the lead.  I’ve used Zend and CakePHP in projects and tried out Symphony but CI actually feels like it aids rapid development instead of being a roadblock. 

Using XML with HTTPService is pretty easy, but the performance of AMF is significant over XML or JSON.  Development time is also lower with an AMF and PHP MVC setup, duplicating business logic gets old and is wasteful.  In the end those are the two selling points for a project.

Thanks again!

 Signature 

Wes Hunt
Web Application Developer and UI Designer
4th Dimension Development

Profile
 
 
   
3 of 3
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 721, on January 06, 2010 09:38 AM
Total Registered Members: 115027 Total Logged-in Users: 65
Total Topics: 122466 Total Anonymous Users: 3
Total Replies: 647381 Total Guests: 457
Total Posts: 769847    
Members ( View Memberlist )