سؤال

AS3 code

<fx:Declarations>
    <!-- this is the RemoteObject  used to make the RPC calls -->
    <mx:RemoteObject id="myRemote" destination="MyService" source="MyService"
       endpoint="http://localhost/amfphp/gateway.php"                
            showBusyCursor="true"/>

</fx:Declarations>

protected function button1_clickHandler(event:MouseEvent):void
{
    var aut:VOAuthor;  // value object class
    aut = new VOAuthor();
    aut.id_aut = 3;
    aut.fname_aut = "test";
    aut.lname_aut = "123";
    myRemote.saveData(aut);
}

Receving PHP code

public function saveData($author) 
{
   $mysql = mysql_connect("localhost", "mx112", "xxxxxx");          
   mysql_select_db("flex360");      
   $query = "INSERT INTO authors (fname_aut, lname_aut) VALUES ('".$author->fname_aut."', '".$author->lname_aut."')";          
   $result = mysql_query($query);                 
   return $author;
}


<?php
class VOAuthor {   
 public $id_aut;    
 public $fname_aut;    
 public $lname_aut;        
 var $_explicitType="org.corlan.VOAuthor";}
?>

Flex network monitor response : Raw view

{lname_aut=123, _explicitType=org.corlan.VOAuthor, fname_aut=test, id_aut=3}

but If I do this at the end of the php code

 return $author->lname_aut;

network monitor response is NULL

so the problem is I can print the array but how to cast tht array to a known php type ? After 5 days I finnaly figured out flex and mysql using amfphp any one please help ?

هل كانت مفيدة؟

المحلول

if you are using amfphp and Flash you have to register your VOs:

import org.corlan.VOAuthor;
// ...
registerClassAlias("org.corlan.VOAuthor", VOAuthor);

only then does php recognize the objects you're sending it from ActionScript.

نصائح أخرى

Yes you need to register your class, and an alternative is to use the metadata tag in the Flex VO declaration.

package VO
{
    [RemoteClass(alias="org.corlan.VOAuthor")]
    public class VOAuthor
    {
        private var id_aut   : int;
        public var fname_aut : String;
        public var lname_aut : String;
...

Hope that helps,

Roger.

PS. A more detailed explanation (that helped me) can be found here: http://www.brentknigge.com/?q=node/499

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top