Writing the PHP code

The Value Object. This needs to be placed in the VO directory of your amfphp installation. See my earlier notes on installation.

AlphaData.php

//********************************************************************
class AlphaData
//********************************************************************
{
public $firstName;
public $lastName;   
public $someInt; 
};

The Services Object. This needs to be placed in the services directory of your amfphp installation. The Alpha PHP class I developed offers 3 methods to return data to Flex.

  • simple_call is used to return a simple string.
  • object_call is used to return an object. In this case I am returning an AlphaData object which I will map to AlphaDataFlex in the Flex code.
  • array_call returns an array of AlphaData objects. Flex will recognize this (from amfphp) as an Array, and I'll bind it to the dataProvider of the dataGrid component.

Alpha.php

require_once 'VO/AlphaData.php';
 
//********************************************************************
class Alpha
//********************************************************************
{
 
 
//--------------------------------------------------------------------
public function __construct()
//--------------------------------------------------------------------
{
 
}
 
 
//-----------------------------------------------------------------
public function simple_call()
//-----------------------------------------------------------------
{
return 'Hello World';
}
 
 
//-----------------------------------------------------------------
public function object_call()
//-----------------------------------------------------------------
{
$data = new AlphaData();
 
$data->firstName = 'brENt';
$data->lastName = 'Knigge';
$data->someInt = 27;
 
return $data;  
}
 
 
//-----------------------------------------------------------------
public function array_call()
//-----------------------------------------------------------------
{
$data1 = $this->object_call();
 
$data2 = new AlphaData();
$data2->firstName = 'Maria';
$data2->lastName = 'Unknown';
$data2->someInt = 25;
 
$data3 = new AlphaData();
$data3->firstName = 'sooty';
$data3->lastName = 'Cat';
$data3->someInt = 9;
 
$data_array = array($data1, $data2, $data3);
return $data_array;
}
 
};
Tags: 

Comments

Hi, This is by far the best example I have seen so far on how to use amfphp 2.1. I have done everything exactly like you (taking care of adding the missing forward slashes where you had to remove them and changing the url to match my system) and I still cannot get it to work. Whenever I press the first two button, I get: ["RPC Fault faultString="error" faultCode="Channel.Call.Failed" faultDetail="NetConnection.Call.Failed: HTTP: Status 500"]. When I press the last button, nothing happens at all. The only thing that is different is that my config file is called services-config.xml instead of config-services.xml because with the later I get a message that the system cannot find the file (either way I suppose it has to do with the command that is in the compiler and any name should work as long as it match the name in the compiler directive). Do you know what could cause this? Thanks

By Eric (not verified)

Hi Eric,

I've tried all sorts of things to try and get a 500 error, but nothing has happened so far. Unfortunately a 500 error is a generic server error, and there is not much I can help you with.

The only thing that is different is that my config file is called services-config.xml instead of config-services.xml. I have updated my tutorial with a better screen shot. All my tutorials now refer to config-services.xml. Thank you for pointing that out.

If you want to email me your entire project I can run it on my system and see if I can find the issue. Just use my my contact form and I'll email you back so that you can attach the project.

Regards,

Brent

By Brent

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.