<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 云自無心水自閑 閱讀(1603) 評論(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
    }
    主站蜘蛛池模板: 亚洲第一se情网站| 亚洲av无码专区在线观看下载| 亚洲A丁香五香天堂网 | 男女啪啪永久免费观看网站| 亚洲福利一区二区精品秒拍| 久久久久免费看黄a级试看 | 中文字幕无码免费久久| 国产亚洲人成网站在线观看| 一出一进一爽一粗一大视频免费的| 亚洲成片观看四虎永久| 黄色网址大全免费| 亚洲综合熟女久久久30p| 免费久久人人爽人人爽av| 亚洲国产成人精品无码区在线观看| 成人无码a级毛片免费| 亚洲av不卡一区二区三区| 亚洲精华国产精华精华液网站| 三级黄色免费观看| 免费看国产成年无码AV片| 亚洲色大成网站www| 免费观看午夜在线欧差毛片 | 久久亚洲AV成人无码国产电影 | 免费永久看黄在线观看app| 欧洲美女大片免费播放器视频| 在线精品亚洲一区二区三区| 青青操视频在线免费观看| 亚洲电影免费在线观看| 男女做羞羞的事视频免费观看无遮挡| 亚洲色欲啪啪久久WWW综合网| 亚洲AV之男人的天堂| 久久永久免费人妻精品下载| 亚洲中文字幕无码中文字| 亚洲国产精品无码久久青草| 久久精品国产免费| 亚洲无mate20pro麻豆| 91av视频免费在线观看| 亚洲AV永久无码天堂影院| 久久久久一级精品亚洲国产成人综合AV区 | 嫩草成人永久免费观看| 亚洲av乱码一区二区三区| 亚洲 无码 在线 专区|