<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉載,體現了我寫此文的意義!!!煩請您在轉載時注明出處http://www.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks
    偶爾寫寫php感覺心情還是蠻舒暢的(Java里的Struts+Hibernate+Spring寫久了),寫寫php才知道,這種被解放的感覺真好。不得不說,php是一種服務器端比較精辟的語言,難怪崇拜者這么多。就來整整flex基于php的交互,看好了,這里要介紹的不是通過flex里面的HttpService組件與php交互,而是借助AMFPHP通過RemoteObject方式來交互。
    關于amfphp環境的搭建,請參考本人寫的amfphp環境搭建教程,當然里面寫的比較粗略,有不清粗的可以聯系我。
    先來看看php端代碼
    ProductServices.php
    <?php
    class ProductServices{
        
    /**
        *query product list
        
    */
        
    function getProductList(){
            
    $link=@mysql_connect("localhost", "root", "") or die("Could not connect");
            
    mysql_select_db("compass",$link);
            
    mysql_query("set names utf8",$link);
            
    $result = mysql_query("SELECT * FROM product",$link);
            
    $array=array();
            
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                
    array_push($array,$row);
            }
            
    mysql_free_result($result);
            
    mysql_close($link);
            
    return $array;
        }



        
    function findProductById($id){
            
    $link=@mysql_connect("localhost", "root", "") or die("Could not connect");
            
    mysql_select_db("compass",$link);
            
    mysql_query("set names utf8",$link);
            
    $result = mysql_query("SELECT * FROM product where id= ".$id,$link);
            
    $array=array();
            
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                
    array_push($array,$row);
            }
            
    mysql_free_result($result);
            
    mysql_close($link);
            
    return $array;
        }

    }
    ?>

    在ProductServices.php文件中,定義了一個類ProductServices,里面封裝了兩個方法,getProductList(),findProductById($id)里面內容很簡單,一個是全部查詢商品,一個是根據Id查詢商品

    注意該文件存放的位置C:\inetpub\wwwroot\amfphp\services\ 這樣可以被amfphp的資源管理器檢索到
     


    編寫flex端代碼
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s
    ="library://ns.adobe.com/flex/spark" 
                   xmlns:mx
    ="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                   creationComplete
    ="ro.getOperation('getProductList').send()"
                   
    >
        
    <!-- 
            ro.getOperation('getProductList').send() 
            ro為RemoteObject的Id
            ro.getOperation('getProductList')獲取php文件中的方法名,及要調用服務器端的那個方法
            send()發送請求,在send中可傳遞參數,多個參數之間用逗號分隔,參數名要與服務器端的參數名一致
        
    -->
        
    <fx:Declarations>
            
    <!-- 將非可視元素(例如服務、值對象)放在此處 -->
            
            
    <s:RemoteObject id="ro" 
                            destination
    ="amfphp"  
                            source
    ="ProductServices" 
                            fault
    ="getProductList_faultHandler(event)" 
                            result
    ="getProductList_resultHandler(event)"
                            endpoint
    ="http://192.168.3.11/amfphp/gateway.php">
            
    </s:RemoteObject>
            
            
    <!--
                RemoteObject中的destination需要與src目錄下的services
    -config.xml中定義的destination的Id保持一致
                source
    ="ProductServices"要調用服務器端的那個php類,如果存在包的話注意包名.類名
                fault 失敗時響應的方法
                result 成功時的方法
                endpoint
    ="http://192.168.3.11/amfphp/gateway.php" 正確訪問gateway.php的地址
            
    -->
            
        
    </fx:Declarations>
        
        
    <fx:Script>
            
    <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.controls.Alert;
                import mx.rpc.events.FaultEvent;
                import mx.rpc.events.ResultEvent;
                import mx.utils.ArrayUtil;
                
                [Bindable]
                internal 
    var dp:ArrayCollection;
                
                
                
                
    //amfphp請求成功時調用方法
                protected function getProductList_resultHandler(event:ResultEvent):void
                {
                    dp
    =new ArrayCollection(ArrayUtil.toArray(event.result));
                }
                
    //amfphp請求失敗時調用方法
                protected function getProductList_faultHandler(event:FaultEvent):void
                {
                    Alert.show(
    "失敗了",event.fault.message);                
                }
                
            ]]
    >
        
    </fx:Script>
        
        
        
    <s:layout>
            
    <s:HorizontalLayout/>
        
    </s:layout>
        
    <s:DataGrid width="519" height="292" dataProvider="{dp}" requestedRowCount="4">
            
    <s:columns>
                
    <s:ArrayList>
                    
    <s:GridColumn dataField="id" headerText="編號"></s:GridColumn>
                    
    <s:GridColumn dataField="name" headerText="商品名稱"></s:GridColumn>
                    
    <s:GridColumn dataField="price" headerText="單價"></s:GridColumn>
                    
    <s:GridColumn dataField="descption" headerText="描述"></s:GridColumn>
                
    </s:ArrayList>
            
    </s:columns>
        
    </s:DataGrid>
        
    </s:Application>

    必須在flex工程的src目錄下存放一個名為services-config.xml
    <? version="1.0" encoding="UTF-8"?>
    <services-config>
        
    <services>
            
    <service id="sabreamf-flashremoting-service"
                     class
    ="flex.messaging.services.RemotingService"
                     messageTypes
    ="flex.messaging.messages.RemotingMessage">
                
    <destination id="amfphp">
                    
    <channels>
                        
    <channel ref="my-amfphp"/>
                    
    </channels>
                    
    <properties>
                        
    <source>*</source>
                    
    </properties>
                
    </destination>
            
    </service>
        
    </services>

        
    <channels>
            
    <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
                
    <endpoint uri="http://192.168.3.11/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
            
    </channel-definition>
        
    </channels>
    </services-config>

    需要將該文件編譯到環境中去

    效果圖

    點我下載代碼
    posted on 2011-10-28 11:52 雪山飛鵠 閱讀(2206) 評論(0)  編輯  收藏 所屬分類: flex+php
    主站蜘蛛池模板: 白白国产永久免费视频| 免费观看在线禁片| 全免费a级毛片免费看无码| 亚洲视频小说图片| 99精品视频免费在线观看| 亚洲无线码在线一区观看| 狠狠躁狠狠爱免费视频无码| 亚洲国产精品无码久久九九| 一级做a爰片久久毛片免费陪 | japanese色国产在线看免费| 亚洲欧洲日产国码www| 99精品热线在线观看免费视频| 亚洲国产一区在线| 足恋玩丝袜脚视频免费网站| 麻豆国产VA免费精品高清在线| 亚洲人成小说网站色| 国产精品视频免费一区二区三区 | 久久精品国产亚洲AV麻豆网站| 91免费福利精品国产| 亚洲成人午夜电影| 午夜电影免费观看| 五月天国产成人AV免费观看| 亚洲人成网77777亚洲色| 99久久精品免费精品国产| 亚洲伊人久久大香线蕉影院| 精品国产精品久久一区免费式| 偷自拍亚洲视频在线观看99| 久久影视国产亚洲| 91成人免费观看| 亚洲成AV人片高潮喷水| 亚洲日韩中文在线精品第一| 亚洲人精品午夜射精日韩| 99re在线视频免费观看| 亚洲精品无码国产片| 毛茸茸bbw亚洲人| 狼群影院在线观看免费观看直播 | 成人久久久观看免费毛片| 亚洲av综合avav中文| 国内一级一级毛片a免费| 久久九九免费高清视频| 亚洲一卡2卡4卡5卡6卡残暴在线|