简体   繁体   English

在flex和php之间传递变量

[英]passing variables between flex and php

i am new to flex development my question is How do i pass variables between flex 3 and a mysql database using php? 我是Flex开发的新手,我的问题是如何使用PHP在flex 3和mysql数据库之间传递变量? i was told the best way is to AMFPHP but that seems like an over kill or may be not am not sure.. any ideas? 有人告诉我最好的方法是使用AMFPHP,但这似乎是一个致命的决定,或者可能不确定。

I'd use json over xml since json will transfer less bytes and php's json_encode($object) is quick and easy. 我会在xml上使用json,因为json会传输较少的字节,而php的json_encode($ object)既快速又容易。

I'd use json over amfphp because json is general purpose. 我会在amfphp上使用json,因为json是通用的。 For example, I can create a web service for flex or javascript by returning json. 例如,我可以通过返回json为flex或javascript创建Web服务。

You might have a look at this article for comparison between json, amfphp, and xml. 您可以看看这篇文章,以比较json,amfphp和xml。 Also, here is a nice tutorial on flex, php, and json. 另外,这是有关flex,php和json的不错的教程

AMFPHP is not really being actively developed. AMFPHP并未真正得到积极开发。 The best alternative right now is to use Zend_Amf http://wadearnold.com/blog/?page_id=155 , which is supported by both Zend and Adobe. 现在最好的选择是使用Zend_Amf http://wadearnold.com/blog/?page_id=155 ,这是Zend和Adobe都支持的。

Don't be scared by the need for Zend Framework components. 不要对Zend Framework组件的需求感到害怕。 The framework is modular, and you can use your own custom php classes for accessing data without having to incur the Zend Framework learning curve. 该框架是模块化的,您可以使用自己的自定义php类来访问数据,而不必引起Zend Framework的学习曲线。

The great thing about using AMF is that since it is a binary data transfer, it's very fast. 使用AMF的好处在于,由于它是二进制数据传输,因此速度非常快。

Also, working with XML or even JSON, is an annoying extra step if you just want your flex app to get results data an api call. 此外,如果您只希望Flex应用程序通过api调用获取结果数据,则使用XML甚至JSON都是一个烦人的额外步骤。 If, for some reason, you need to also handle outputting data to xml or json, that can easily be added to your app by extending or creating new controllers/services that translate the data from arrays and objects to xml or json 如果由于某种原因,您还需要处理将数据输出到xml或json的情况,那么可以通过扩展或创建新的控制器/服务来轻松地将数据输出到您的应用程序中,以将数据从数组和对象转换为xml或json

There's a few choices open to you. 有几个选择供您选择。 Essentially, it boils down to how you'd like to deal with the data on the PHP side of the fence. 本质上,它归结为您希望如何处理围栏的PHP一侧的数据。

The two I'd spend time investigating would be simple XML (my first preference) and AMFPHP. 我花时间研究的两个是简单的XML(我的首选)和AMFPHP。

XML: Flex can work very easily with XML data, even mapping it automatically to/from ActionScript objects (generically, or with something like the xobj project on GoogleCode , to typed instances). XML:Flex可以非常轻松地使用XML数据,甚至可以将其自动映射到ActionScript对象或从ActionScript对象自动映射(通常,或者使用诸如GoogleCode上xobj项目之类的东西,到类型化实例)。 Similarly, there's plenty of support available for working with XML in PHP code. 同样,在PHP代码中使用XML有很多支持。

AMFPHP: AMFPHP gives you way to pass typed ActionScript objects over the wire to your PHP code. AMFPHP:AMFPHP使您可以通过电线将类型化的ActionScript对象传递给您的PHP代码。 There's tooling included in the AMFPHP project that makes working with MySQL on the PHP side easy too. AMFPHP项目中包含的工具也使在PHP方面使用MySQL变得容易。

If you are doing a simple query, I would pass your data as plain POST data. 如果您要进行简单的查询,我会将您的数据作为纯POST数据进行传递。 You can do this using HTTPService component in Flex. 您可以使用Flex中的HTTPService组件执行此操作。 On the PHP side I would respond with an XML string and set the HTTPService resultFormat to "e4x" (Ecmascript for XML), for an easy object-like manipulation of the result data. 在PHP方面,我将使用XML字符串进行响应,并将HTTPService resultFormat设置为“ e4x”(XML的Ecmascript),以便对结果数据进行类似于对象的简单操作。

Here is the livedocs reference for HTTPService: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_2.html 这是HTTPService的livedocs参考: http : //livedocs.adobe.com/flex/3/html/help.html? content= data_access_2.html

For more complicated queries/operations, there is also the option of using the Flex RemoteObject with AMF as the data protocol. 对于更复杂的查询/操作,还可以选择将带有AMF的Flex RemoteObject与数据协议一起使用。 On the PHP side you can then use the zend framework AMF component to communicate. 在PHP方面,您可以使用zend框架AMF组件进行通信。

Here is the livedocs reference for RemoteObject: http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html 这是RemoteObject的livedocs参考: http : //livedocs.adobe.com/flex/3/html/help.html? content= data_access_4.html

And the download page for Zend AMF: http://framework.zend.com/download/amf 以及Zend AMF的下载页面: http : //framework.zend.com/download/amf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM