使用 Zend_Amf 为我的 Flex 应用程序提供不同的服务
我有一个迭代器服务,它已经可以正常工作,并通过我的 Zend Amf 服务器向我的 Flex 应用程序返回一个结构正确的值,
$contacts = array();
mysql_connect( 'localhost', 'root', 'test' );
mysql_select_db( 'test' );
$res = mysql_query( 'SELECT * FROM contact' );
while( $contact = mysql_fetch_assoc($res) ) {
$contacts []= $contact;
}
return $contacts;
但是我想对此进行调整,以便我可以利用和我的MVC结构达到同样的效果。 我已经放置了可以进入工作状态的摘录
$contacts = array();
$table = new Model_DbTable_Contact();
$result = $table->fetchAll();
//Return an array to be consumed by my flex application
foreach ($result as $row)
{
/*do something*/
}
return $contacts;
I have an iterator service that works fine already and returns a correctly structured values to my flex application through my Zend Amf server
$contacts = array();
mysql_connect( 'localhost', 'root', 'test' );
mysql_select_db( 'test' );
$res = mysql_query( 'SELECT * FROM contact' );
while( $contact = mysql_fetch_assoc($res) ) {
$contacts []= $contact;
}
return $contacts;
However I would like to adjust this so that I can leverage my MVC structure and achieve the same results.
I have placed an excerpt that can be brought to working condition
$contacts = array();
$table = new Model_DbTable_Contact();
$result = $table->fetchAll();
//Return an array to be consumed by my flex application
foreach ($result as $row)
{
/*do something*/
}
return $contacts;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要研究 ValueObjects。 Zend_Amf 支持这些,使用它是一个好主意。这样您就可以拥有 PHP 和 Flex 原生的对象。
然后,您的 Flex 将有一个类:
告诉您的服务器您要将 Contact 类映射到 Flex 中的 ContactVO。
那么你可以这样做:
你的 Contact 对象将作为 ContactVO 对象到达 Flex
You'll want to look into ValueObjects. Zend_Amf supports those, and it's a good idea to use that. That way you can have objects that are native to both PHP and Flex.
Your Flex would then have a class:
Would tell your server that you're going to map your Contact class to ContactVO in Flex.
then you could do:
and your Contact objects would get to Flex as ContactVO objects
所以这里我在数据库表的逻辑模型中有一个函数:
public function fetchAll() {
So here I have a function in the logical model for a database table:
public function fetchAll() {