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

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

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

    云自無心水自閑

    天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
    posts - 288, comments - 524, trackbacks - 0, articles - 6
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    Flex2通過amfphp與PHP的整合調用

    Posted on 2006-06-01 17:33 云自無心水自閑 閱讀(1600) 評論(4)  編輯  收藏 所屬分類: FlexFlex2
    一。安裝amfphp,
    1. 下載ampfphp1.2版本
    2. 建立一個目錄amfphp, 將包中的文件解壓到此目錄中。
    3. 目錄結構舉例如下:
    c:\amfphp\amf-core
    c:\amfphp\browser
    c:\amfphp\services
    c:\amfphp\gateway.php
    在Http Server中(可以是IIS,Apache Http Server)中建立一個虛擬目錄,映射c:\amfphp
    4. 驗證
    在瀏覽器中輸入 http://localhost/amfphp/gateway.php
    會看到一個成功頁面。

    二。編寫PHP端代碼
    舉個例子:定義一個sample類,這個類編寫在sample.php中
    其中定義一個getUsers方法
    這個php文件放在amfphp\services\中。
    <?php
    // Create new service for PHP Remoting as Class
    class sample
    {
    ??????? function sample ()
    ??????? {
    ??????????????? // Define the methodTable for this class in the constructor
    ??????????????? $this->methodTable = array(
    ??????????????????????????????? "getUsers" => array(
    ??????????????????????????????? "description" => "Return a list of users",
    ??????????????????????????????? "access" => "remote"
    ??????????????????????? )
    ??????????????? );
    ??????? }

    ??????? function getUsers ($pUserName) {
    ??????????????? $mysql = mysql_connect(localhost, "username", "password");
    ??????????????? mysql_select_db( "sample" );
    ??????????????? //return a list of all the users
    ??????????????? $Query = "SELECT * from users";
    ??????????????? $Result = mysql_query( $Query );
    ??????????????? while ($row = mysql_fetch_object($Result)) {
    ??????????????????????? $ArrayOfUsers[] = $row;
    ??????????????? }
    ??????????????? return( $ArrayOfUsers );
    ??????? }
    }
    ?>
    驗證:
    在瀏覽器中輸入http://localhost/amfphp/browser/index.html
    會發現在左邊Frame中有一個sampe的鏈接,點擊后,在右邊Frame中可以測試此方法。

    三。編寫Flex端代碼
    首先寫一個RemotingConnection類,繼承自NetConnection,主要是用于統一指定編碼格式
    package
    {
    ??????? import flash.net.NetConnection;
    ??????? import flash.net.ObjectEncoding;
    ?????? ?
    ??????? public class RemotingConnection extends NetConnection
    ??????? {
    ??????????????? public function RemotingConnection( sURL:String )
    ??????????????? {
    ??????????????????????? objectEncoding = ObjectEncoding.AMF0;
    ??????????????????????? if (sURL) connect( sURL );
    ??????????????? }
    ?????????????? ?
    ??????????????? public function AppendToGatewayUrl( s : String ) : void
    ??????????????? {
    ??????????????? }
    ??????? }
    }
    然后在應用中可以進行如下調用:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="initApplication()">
    ??????? <mx:DataGrid dataProvider="{dataProvider}">
    ??????????????? <mx:columns>
    ??????????????????????????????? <mx:DataGridColumn headerText="Userid" dataField="userid"/>
    ??????????????????????????????? <mx:DataGridColumn headerText="User Name" dataField="username"/>
    ??????????????????????????????? <mx:DataGridColumn headerText="User Name" dataField="emailaddress"/>
    ??????????????????????? </mx:columns>
    ??????? </mx:DataGrid>
    ??????? <mx:Script>
    ??????????????? <![CDATA[
    ??????????????????????? import mx.controls.Alert;
    ??????????????????????? [Bindable]
    ??????????????????????? public var dataProvider:Array;
    ?????????????????????? ?
    ??????????????????????? import flash.net.Responder;
    ?
    ??????????????????????? public var gateway : RemotingConnection;
    ?????????????????????? ?
    ??????????????????????? public function initApplication() : void
    ??????????????????????? {
    ??????????????????????????????? gateway = new RemotingConnection( "http://localhost/amfphp/gateway.php" );
    ??????????????????????????????? gateway.call( "sample.getUsers", new Responder(onResult, onFault));
    ??????????????????????? }
    ?????????????? ?
    ??????????????????????? public function onResult( result : Array ) : void
    ??????????????????????? {
    ??????????????????????????????? dataProvider = result;
    ??????????????????????????????? // mx.controls.Alert.show("result: " + result.toString());
    ??????????????????????? }
    ?????????????????????? ?
    ?????????????????????? ?
    ??????????????????????? public function onFault( fault : String ) : void
    ??????????????????????? {
    ??????????????????????????????? // trace( fault );
    ??????????????????????????????? mx.controls.Alert.show(fault);
    ??????????????????????? }
    ??????????????? ]]>
    ??????? </mx:Script>
    </mx:Application>

    補充說明:如果調用的PHP函數需要參數,比如:getUsers($user_name)
    那么可以在Flex調用端,需要相應的添加此參數:
    gateway.call( "sample.getUsers", new Responder(onResult, onFault), "<username>");


    評論

    # re: Flex2通過amfphp與PHP的整合調用  回復  更多評論   

    2006-06-01 17:36 by dudu
    該文應該放在其他技術區。

    # re: Flex2通過amfphp與PHP的整合調用  回復  更多評論   

    2006-06-06 08:48 by usherlight
    OK.

    # re: Flex2通過amfphp與PHP的整合調用  回復  更多評論   

    2006-08-02 23:32 by Goacross
    不是還要一個數據庫嗎?能否給出完整示例下載?

    # re: Flex2通過amfphp與PHP的整合調用  回復  更多評論   

    2006-08-08 15:26 by usherlight
    create table users {
    id int,
    name varchar(50),
    age int,
    birthday Date
    }
    主站蜘蛛池模板: 亚洲精品福利视频| 日韩成人精品日本亚洲| 免费观看黄网站在线播放| 国产精品成人亚洲| 亚洲AV乱码久久精品蜜桃| 少妇高潮太爽了在线观看免费| 日韩成人精品日本亚洲| 亚洲国产精品久久久久久| 日韩激情淫片免费看| 叮咚影视在线观看免费完整版| 亚洲高清一区二区三区| 亚洲精品无码久久久久| 精品久久久久国产免费| 免费看一区二区三区四区| 亚洲av成人一区二区三区观看在线 | 亚洲日韩乱码中文无码蜜桃臀网站 | 亚洲中文无码线在线观看| 亚洲第一视频在线观看免费| 18女人水真多免费高清毛片| 黄页网址在线免费观看| 亚洲综合色丁香麻豆| 国产成人亚洲精品狼色在线| 天天摸天天操免费播放小视频| 国产猛男猛女超爽免费视频| 亚洲a∨无码一区二区| 亚洲美女免费视频| 亚洲愉拍99热成人精品热久久| 四虎成人免费大片在线| 麻花传媒剧在线mv免费观看| 国产免费福利体检区久久| 亚洲AV色无码乱码在线观看| 亚洲高清无在码在线无弹窗| 亚洲日产韩国一二三四区| 免费欧洲美女牲交视频| 成人影片麻豆国产影片免费观看 | 一本色道久久88综合亚洲精品高清| 亚洲免费电影网站| 久久一本岛在免费线观看2020| 午夜成人无码福利免费视频| 亚洲乱码无人区卡1卡2卡3| 亚洲一级片在线观看|