micha,
i will try to tell you as much as i know about it. i am very new to flash remoting and amfphp (couple of days). so if i make mistakes or the like, more knowledgable folk should correct me.
the method table is used to tell flash what functions (i.e. methods) are available from a service.
in the service browser you can add the discovery.php as a gateway. then add dbservice.php (put it in the services directory) as a service. now all the functions available from that service are listed.
note that the service php has to have the same name as the class name (dbservice.php <> class dbservice).
what i also found is that the number of arguments you send to a function should be reflected in the
"arguments" => array ("arg1","arg2")
statement. if you send to many args, an error will be raised.
i don't know much about the method table. it works for me, but i would also appreciate if someone could give us an in-depth explanation of it.
hope this helped.
cheers,
cmyk
discovery.php on root of flashservices:
<?
include "app/gateway.php";
$gateway = new Gateway();
$gateway->setBaseClassPath("services/");
$gateway->service();
?>
this is my dbservice.php (flashservices/services/dbservice.php)
<?
class dbservice{
function dbservice(){
$this->conn = mysql_pconnect("localhost","xxxxx","xxxxx");
mysql_select_db("test_amf");
// method table
$this->methodTable = array(
"getAll" => array(
"description" => "Get all the entries from the addressbook",
"access" => "remote",
"roles" => "role, getAll",
"returntype" => "mysql result",
"arguments" => array ("arg1")
),
"updateRecord" => array(
"description" => "updates the selected Record",
"access" => "remote",
"roles" => "role, updateRecord",
"returntype" => "array",
"arguments" => array ("arg1")
),
"createRecord" => array(
"description" => "creates a new Record",
"access" => "remote",
"roles" => "role, createRecord",
"returntype" => "string",
"arguments" => array ("arg1")
),
"deleteRecord" => array(
"description" => "Deletes a Record",
"access" => "remote",
"roles" => "role, deleteRecord",
"returntype" => "string",
"arguments" => array ("arg1")
)
);
}
// dbservice methods
function getAll(){
return mysql_query("SELECT * FROM addressbook");
}
function updateRecord($arg){
$sql ="UPDATE addressbook SET ".
"firstName = '".$arg[1]."', ".
"lastName = '".$arg[2]."', ".
"street = '".$arg[3]."', ".
"streetNumber = '".$arg[4]."', ".
"town = '".$arg[5]."', ".
"phoneNumber = '".$arg[6]."'".
" WHERE ID = '".$arg[0]."'";
$result=mysql_query($sql);
if ($result) {
return mysql_affected_rows()." records updated.!";
} else {
return "FAILURE! Could not update the table! " . "ERROR nr. ". mysql_errno().": ". mysql_error();
}
}
function createRecord($arg){
$sql ="INSERT INTO addressbook (firstName, lastName, street, streetNumber, town, phoneNumber)" .
" values ('" . $arg[1] . "', '" . $arg[2] . "', '" . $arg[3] . "', '" . $arg[4] . "', '" . $arg[5] . "', '" . $arg[6] ."')";
$result=mysql_query($sql);
if ($result) {
return mysql_affected_rows(). "new record(s) inserted!";
} else {
return "FAILURE! Could not update the table!";
}
}
function deleteRecord($arg){
$sql ="DELETE FROM addressbook WHERE ID = '".$arg."'";
$result=mysql_query($sql);
if ($result) {
return mysql_affected_rows()." record(s) DELETED!";
} else {
return "FAILURE! Could not update the table!";
}
}
?>