0 Replies Latest reply on Feb 21, 2010 1:01 PM by Luis Pedro Ferreira

    AMFPHP - Sending data to Flex

    Luis Pedro Ferreira Level 1

      Since i start using AMFPHP, i've been seeing different ways to send data to Flex, two of them is sending an ArrayCollection containing all the data another way is using VO's, or sending objects each one with one row of my query (am i correct?).

       

      Now, what's the difference between sending the query results in an ArrayCollection (1000 records means 1 ArrayCollection) and sending a bunch of objects (1000 records means 1000 objects) to Flex with RemoteObject?

       

      Sending an ArrayCollection the data goes like this:

        [0] (Object)#1
          color_code = "0x9999"
          color_id = "8"
        [1] (Object)#2
          color_code = "0xCC99CC"
          color_id = "7"
        [2] (Object)#3
          color_code = "0xFF9999"
          color_id = "10"
        [3] (Object)#4
          color_code = "0xFFCC66"
          color_id = "9"

       

      And the PHP code is this one:

      public function all_colors_array(){
           $db=$this->connection();
           $rs=$db->Execute("SELECT * FROM colors WHERE color_status=1 ORDER BY color_code ASC");
           $i=0;
           while (!$rs->EOF){
                $color_code[$i]['color_id'] = $rs->fields['color_id'];
                $color_code[$i]['color_code'] = $rs->fields['color_code'];
                $rs->MoveNext();
                $i++;
           }
           return $color_code;
      }

       

      Sending as Objects, it goes like this:

        [0] (Object)#1
          color_code = "0x9999"
          color_id = "8"
          color_status = "1"
        [1] (Object)#2
          color_code = "0xCC99CC"
          color_id = "7"
          color_status = "1"
        [2] (Object)#3
          color_code = "0xFF9999"
          color_id = "10"
          color_status = "1"
        [3] (Object)#4
          color_code = "0xFFCC66"
          color_id = "9"
          color_status = "1"

       

      And the PHP is like this after including the VO file:

      include_once '../vo/ColorVO.php';

      .......

      public function all_colors_objects(){
           $db=$this->connection();
           $rs=$db->Execute("SELECT * FROM colors WHERE color_status=1 ORDER BY color_code ASC");
           while (!$rs->EOF){
                $color = new ColorVO();
                $color->color_id = $rs->fields['color_id'];
                $color->color_code = $rs->fields['color_code'];
                $color->color_status = $rs->fields['color_status'];
                $a[]=$color;
                $rs->MoveNext();
           }
      return $a;
      }

       

      Now:

      1. What's the difference?

      2. Which one is best pratices?

      3. Which one is better? ans Why?

      4. If is there anything wring with my code please fell free to correct it!!