<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 雪山飛鵠 閱讀(2201) 評論(0)  編輯  收藏 所屬分類: flex+php
    主站蜘蛛池模板: 亚洲精品亚洲人成在线| 99爱免费观看视频在线| 亚洲日韩小电影在线观看| 最近免费中文字幕大全高清大全1| 亚洲人成在线中文字幕| 全亚洲最新黄色特级网站| 性无码免费一区二区三区在线| 国产成人亚洲综合网站不卡| 亚洲综合另类小说色区色噜噜| 最近在线2018视频免费观看| 精品成人一区二区三区免费视频 | 亚洲伊人久久大香线蕉苏妲己| 国产精品视频免费一区二区| 国产精品99爱免费视频| 亚洲人成7777| 国产亚洲无线码一区二区| 四虎国产精品免费久久| 国产精品免费看久久久香蕉| 亚洲中文无码mv| 久久亚洲免费视频| 亚洲av高清在线观看一区二区| 精品无码免费专区毛片| 亚洲免费在线观看| 亚洲精品亚洲人成在线| 亚洲欧洲精品在线| 亚洲精品无码久久久影院相关影片| 成人免费视频一区| 最近2019中文字幕免费直播| 国产精品99爱免费视频| 亚洲国产成人无码AV在线| 亚洲视频免费在线播放| 中文字幕日韩亚洲| 日韩电影免费在线观看视频| 7x7x7x免费在线观看| a毛片免费全部播放完整成| 国产产在线精品亚洲AAVV| jlzzjlzz亚洲jzjzjz| 亚洲国产精品免费视频| 亚洲一区二区三区在线观看精品中文| 免费鲁丝片一级在线观看| 免费看韩国黄a片在线观看|