【发布时间】:2011-07-16 10:10:02
【问题描述】:
好的 - 所以我一直在到处寻找并试图纠正这个问题 - 但我一直在寻找不同的答案,坦率地说,试图弄清楚这一点变得非常令人沮丧。让我发布一些代码供您查看:
PHP 脚本:
public function addNewCompany(CompanyVO $item)
{
$stmt = mysqli_prepare($this->connection,
"INSERT INTO `companies` ('companyName') VALUES (?);");
$this->throwExceptionOnError();
mysqli_bind_param($stmt, 's', $item->companyName);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}
MXML 主应用程序的部分:
protected function companysignupsheet1_addCompanyEventHandler(event:AddCompanyEvent):void
{
companyservicero.addNewCompany({Data:event.companyData});
}
<s:RemoteObject id="companyservicero"
source="CompanyServices"
destination="addNewCompany"
endpoint = "http://localhost/PHP_RO/public/gateway.php"
result="companyservicero_resultHandler(event)"
fault="companyservicero_faultHandler(event)"/>
来自组件的部分代码:
protected function button_submitNewCompany_clickHandler(event:MouseEvent):void
{
var companyData11:CompanyVO = new CompanyVO();
companyData11.companyName = textinput_NewCompanyName.text;
var eventObject:AddCompanyEvent = new AddCompanyEvent("addCompanyEvent", companyData11);
dispatchEvent(eventObject);
}
事件:
package events
{
import flash.events.Event;
import valueObjects.CompanyVO;
public class AddCompanyEvent extends Event
{
public var companyData:CompanyVO;
public function AddCompanyEvent(type:String, companyData:CompanyVO)
{
super(type);
this.companyData = companyData;
}
}
}
如果我需要发布更多内容,我会很乐意这样做。另外 - 我知道尝试以这种方式发送一个文本值有点矫枉过正,但是当我让它工作时会有很多很多的东西 - 我只是试图专注于问题是。哦 - 我不知道它是否有帮助......但目前我可以从它所连接的 mySQL 数据库中检索记录(虽然我不是通过 RemoteObject 方式这样做) - 我也可以添加到相同的使用上述 PHP 的精确副本的旧拖放(连接到数据/服务)功能的表格(尽管信息硬编码在(即 CompanyName=testtest)中)。
为了完成这一切——早些时候我没有为参数定义数据类型:
public function addNewCompany($item){.....
对于 addNewCompany - 它确实在数据库中添加了一条记录,虽然它是空白的,但它仍然会弹出一条带有整个 Channel.Connect 等的错误消息......现在在 Zend Server 的日志中它说数据在 stdClass 包装器中传输,在 CompanyVO 数据类型中是必需的。
我对这一切感到非常沮丧 - 我已经被这类问题困扰了大约 2-3 天,我放弃了!请帮忙。非常感谢您的时间和帮助!
-CS
编辑 - 更多信息
GATEWAY.PHP
<?php
ini_set("display_errors", 1);
$dir = dirname(__FILE__);
$webroot = $_SERVER['DOCUMENT_ROOT'];
$configfile = "$dir/amf_config.ini";
$servicesdir = $dir.'/../services';
$librarydir = $dir.'/../library';
//default zend install directory
$zenddir = $webroot.'/ZendFramework/library';
//Load ini file and locate zend directory
if (file_exists($configfile)) {
$arr = parse_ini_file($configfile, true);
if (isset($arr['zend']['webroot'])) {
$webroot = $arr['zend']['webroot'];
$zenddir = $webroot.'/ZendFramework/library';
}
if (isset($arr['zend']['zend_path'])) {
$zenddir = $arr['zend']['zend_path'];
}
if (isset($arr['zend']['library'])) {
$librarydir = $arr['zend']['library'];
}
if (isset($arr['zend']['services'])) {
$servicesdir = $arr['zend']['services'];
}
}
// Setup include path
// add zend directory, library and services to include path
set_include_path(get_include_path()
.PATH_SEPARATOR.$zenddir
.PATH_SEPARATOR.$librarydir
.PATH_SEPARATOR.$servicesdir);
// Initialize Zend Framework loader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true)- >suppressNotFoundWarnings(true);
// Load configuration
$default_config = new Zend_Config(array("production" => false), true);
$default_config->merge(new Zend_Config_Ini($configfile, 'zendamf'));
$default_config->setReadOnly();
$amf = $default_config->amf;
// Store configuration in the registry
Zend_Registry::set("amf-config", $amf);
// Initialize AMF Server
$server = new Zend_Amf_Server();
$server->setProduction($amf->production);
if (isset($amf->directories)) {
$dirs = $amf->directories->toArray();
foreach ($dirs as $dir) {
if ($dir == "./") {
$server->addDirectory($webroot);
} else
if (realpath("{$webroot}/{$dir}")) {
$server->addDirectory("{$webroot}/{$dir}");
} else
if (realpath($dir)) {
$server->addDirectory(realpath($dir));
}
}
}
// Initialize introspector for non-production
if (! $amf->production) {
$server->setClass('Zend_Amf_Adobe_Introspector', '',
array("config" => $default_config, "server" => $server));
$server->setClass('Zend_Amf_Adobe_DbInspector', '',
array("config" => $default_config, "server" => $server));
}
// Handle request
echo $server->handle();
AMF_CONFIG
[zend]
;set the absolute location path of webroot directory, example:
;Windows: C:\apache\www
;MAC/UNIX: /user/apache/www
webroot = "C:/Zend/Apache2/htdocs"
;set the absolute location path of zend installation directory, example:
;Windows: C:\apache\PHPFrameworks\ZendFramework\library
;MAC/UNIX: /user/apache/PHPFrameworks/ZendFramework/library
zend_path ="C:/Zend/Apache2/htdocs/.metadata/.plugins/org.zend.php.framework.resource/resources/ZendFramework-1/library"
library ="C:/Zend/Apache2/htdocs/PHP_RO/library"
services ="C:/Zend/Apache2/htdocs/PHP_RO/services"
[zendamf]
amf.production = false
amf.directories[]=PHP_RO/services
【问题讨论】:
-
请发布您的服务配置/频道定义xml?
-
我不知道那在哪里。我已经在我的系统上进行了搜索。我能找到的唯一一个是 gateway.php 和 amf_config。也许您正在寻找其中之一...?我会把它们贴出来看看是不是。
-
更新:查看发送到 PHP 脚本的原始视图是:
-
服务请求:addNewCompany;远程服务; addNewCompany (mx.messaging.messages::RemotingMessage)#0 body = (Array)#1 [0] (Object)#2 CompanyVO = (valueObjects::CompanyVO)#3 companyName = "asdf" clientId = (null) destination = "" headers = (Object)#4 DSRemoteCredentials = "" DSRemoteCredentialsCharset = (null) messageId = "54D01758-6CE2-C4FC-58DF-340A73ABC0A7" operation = "addNewCompany" source = "CompanyServices" 时间戳 = 0 timeToLive = 0
标签: php mysql apache-flex serialization flash-builder