使用 Zend_Amf 为我的 Flex 应用程序提供不同的服务

发布于 2024-08-20 02:42:48 字数 699 浏览 6 评论 0原文

我有一个迭代器服务,它已经可以正常工作,并通过我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

变身佩奇 2024-08-27 02:42:48

您需要研究 ValueObjects。 Zend_Amf 支持这些,使用它是一个好主意。这样您就可以拥有 PHP 和 Flex 原生的对象。

$server->setClassMap('ContactVO', 'Contact');

然后,您的 Flex 将有一个类:

[Bindable]
[RemoteClass(alias="Contact")]
public class ContactVO
{
}

告诉您的服务器您要将 Contact 类映射到 Flex 中的 ContactVO。

那么你可以这样做:

$data = array();
foreach ($result as $row)
{
    $data[] = new Contact($row); 
    //assuming the Contact constructor parses the array data
}
return $data;

你的 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.

$server->setClassMap('ContactVO', 'Contact');

Your Flex would then have a class:

[Bindable]
[RemoteClass(alias="Contact")]
public class ContactVO
{
}

Would tell your server that you're going to map your Contact class to ContactVO in Flex.

then you could do:

$data = array();
foreach ($result as $row)
{
    $data[] = new Contact($row); 
    //assuming the Contact constructor parses the array data
}
return $data;

and your Contact objects would get to Flex as ContactVO objects

凡间太子 2024-08-27 02:42:48

所以这里我在数据库表的逻辑模型中有一个函数:

public function fetchAll() {

    $resultSet = $this->getDbTable()->fetchAll();
    $entries = array();
    foreach( $resultSet as $row ) {
        $entry = new Model_ClosingData();

        $entry->setId($row->id)
              ->setContractMonth($row->monthId)
              ->setCommodity($row->commodityId)
              ->setDate($row->date)
              ->setPrice($row->price)
              ->setVolume($row->volume)
              ->setOutstandingInterest($row->outstandingInterest);
        $entries[] = $entry;
    }
    return $entries;
}

So here I have a function in the logical model for a database table:

public function fetchAll() {

    $resultSet = $this->getDbTable()->fetchAll();
    $entries = array();
    foreach( $resultSet as $row ) {
        $entry = new Model_ClosingData();

        $entry->setId($row->id)
              ->setContractMonth($row->monthId)
              ->setCommodity($row->commodityId)
              ->setDate($row->date)
              ->setPrice($row->price)
              ->setVolume($row->volume)
              ->setOutstandingInterest($row->outstandingInterest);
        $entries[] = $entry;
    }
    return $entries;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文