日期:2014-05-16  浏览次数:20378 次

phprpc _很好很好用的_flex与后台数据库通信的桥梁
今天刚试验了phprpc作为flex 与数据库打交道的一系列添加,删除,修改操作。感觉爽呆了,很好。由于刚写好,代码有些冗余,见笑了。以后再慢慢优化。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
    <![CDATA[
        import org.phprpc.PHPRPC_Error; 
        import org.phprpc.PHPRPC_Client;//import PHPRPC_Client 
        import mx.controls.Alert;
       
    private function init():void{

     var rpc:PHPRPC_Client = new PHPRPC_Client('http://localhost/flex/phprpc/server/getUsers.php', ['getUsers']); 


       rpc.getUsers(function (result:*, args:Array, output:String, warning:PHPRPC_Error):void { 
   
       //var i:int;          
      // var users:Array = new Array();
             
       //for(i=0;i<result.length;i++){      
                       
     //    users.push(result[i]);
     //  }
       dgusers.dataProvider=result;//把数据源绑定到列表中
      });               
   }
        public function edit():void{
         //Alert.show(dgusers.selectedItem.id);
         var eid:String=dgusers.selectedItem.id;
         var name:String=user_name.text;
         var password:String=user_psw.text;
        
         //Alert.show(eid);
         //Alert.show(name);
         //Alert.show(password);
        
        
         var rpc:PHPRPC_Client = new PHPRPC_Client('http://localhost/flex/phprpc/server/editUsers.php', ['editUsers']);
        
         rpc.editUsers(eid,name,password,function (result:*, args:Array, output:String, warning:PHPRPC_Error):void { 
         if(result){
           Alert.show("ok");
    
             var rpc:PHPRPC_Client = new PHPRPC_Client('http://localhost/flex/phprpc/server/getUsers.php', ['getUsers']); 


               rpc.getUsers(function (result:*, args:Array, output:String, warning:PHPRPC_Error):void { 
   
               dgusers.dataProvider=result;//把数据源绑定到列表中
          }); 
         }