2008-03-22

使用 Flash CS3 製作 Flex 的組件


  1. http://www.adobe.com/go/flex3_cs3_swfkit 下載 Flex Component Kit for Flash CS3 (也可以一併下載 Flex Skin Design Extensions)

  2. 使用 Extension Manager 安裝如這篇說明 Installing the Flex Component Kit for Flash CS3

  3. nick velloff 的製作範例在 Flex Component Kit Examples, MAX 2007 Chicago Presentation

2008-03-10

在 CodeIgniter 裡建立 SabreAMF 的 gateway

承上一篇 結合 CodeIgniter 和 SabreAMF
接著是建立 gateway, 請參考 Using Flex 2 RemoteObject and SabreAMFGetting started with SabreAMF 的作法。
我們會將 gateway 放在 Controllers 裡。Server side remoting 程式則是放在 Models 裡。
在 ci_project/system/application/controllers/ 新增檔案 gateway.php
<?php
class Gateway extends Controller {
function Gateway()
{
parent::Controller();
}

function index()
{
require_once('SabreAMF/CallbackServer.php');
try {
$callbackServer = new SabreAMF_CallbackServer();
$callbackServer->onInvokeService = array($this, 'invokeService');
$callbackServer->exec();
}catch(Exception $e){
echo $e->getMessage();
}
}

function invokeService($service, $method, $data) {
$modelPath = str_replace( '.', '/', $service);
$this->load->model($modelPath, 'amf_model');
return call_user_func_array( array( $this->amf_model, $method ), $data );
}
}
?>

測試的 Models 放在 ci_project/system/application/models/test/test_model.php
<?php
class Test_model extends Model
{
function Test_model()
{
parent::Model();
}

function myMethod($d1, $d2)
{
$ret = array(
array( 'ID' => $d1, 'name' => 'okok', 'phone' => $d2 ),
array( 'ID' => '35712', 'name' => 'Esbd V. Mb', 'phone' => '235-4263' ),
array( 'ID' => '46823', 'name' => 'Ftce W. Nc', 'phone' => '346-5374' ),
);
return $ret;
}
}
?>

Flash CS3 AS3 的 client 測試
import fl.data.DataProvider;
var nc:NetConnection = new NetConnection();
//nc.objectEncoding = ObjectEncoding.AMF3;

var onResult:Function = function(result:Object) {
QopDump.echo(result);
dg.dataProvider = new DataProvider(result);
};
var onStatus:Function = function(info:Object) {
QopDump.echo(info);
};
var responder:Responder = new Responder(onResult, onStatus);
nc.connect("http://localhost/ci/?/gateway");

nc.call("test.Test_model.myMethod", responder, ["888", "666"]);

Flex 的 client 測試
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:RemoteObject id="ro"
destination=" "
endpoint="http://localhost/ci/?/gateway"
source="test.Test_model"
result="resultHandler( event )"
fault="faultHandler( event )">
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import mx.rpc.events.*;
import mx.controls.Alert;
import mx.rpc.*;

private function load():void {
ro.myMethod('first','123-456789');
}
private function resultHandler( event:ResultEvent ):void {
Alert.show( QopDump.go(event.result) );
dg.dataProvider = event.result;
}
private function faultHandler( event:FaultEvent ):void {
Alert.show( event.toString() );
}
]]>
</mx:Script>
<mx:Button click="load()" label="Load" />
<mx:DataGrid id="dg" />
</mx:Application>

結合 CodeIgniter 和 SabreAMF

參考這篇 將 Zend Framework 放進 CodeIgniter
將符合 PEAR 規定的 library 掛上 CodeIgniter
1. 設定 config
修改 ci_project/system/application/config/config.php
$config['enable_hooks'] = TRUE;


2. 增加 hooks 設定
於 ci_project/system/application/config/hooks.php 增加
$hook['pre_controller'][] = array(
'class' => 'Pearroot',
'function' => 'index',
'filename' => 'pearroot.php',
'filepath' => 'hooks',
);


3. 增加 hooks 程式
於 ci_project/system/application/hooks/ 裡增加 pearroot.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pearroot
{
function index()
{
set_include_path(get_include_path() . PATH_SEPARATOR . BASEPATH . 'pearroot/');
}
}
?>


4. 放置 SabreAMF 目錄
建立 ci_project/system/pearroot/ 目錄並將 SabreAMF/ 放置其底下, 就完成初步的設定。
下一篇 在 CodeIgniter 裡建立 SabreAMF 的 gateway

FB 留言