2 Replies Latest reply on Feb 18, 2009 8:33 AM by Gregory Lafrance

    Processing ArrayCollection or XML in PHP from Flex

    Gregory Lafrance Level 6
      I know this is a Flex forum, but after I use HTTPService with POST and an ArrayCollection or XML object as the parameter, anybody have the PHP code I would use to grab the parameter on the server side?

      Once I have grabbed it and put it in a PHP variable I can figure out the rest.

      Thanks!
        • 1. Re: Processing ArrayCollection or XML in PHP from Flex
          flexstone Level 1
          One caveat for POST ing XML from AIR is that there is a bug and it submits as GET instead. Work-around I had to use was to upload XML file instead and then parse it.... otherwise from FLEX


          If you POST the XML as a parameter like so

          var params:Object = new Object()
          params.postText = myXML
          myHTTPService.send(params)

          and your XML is something like.....

          <root>
          <record><data>mydata</data></record>
          </root>

          then the PHP script looks something like.........

          foreach($_POST AS $key => $value) { ${$key} = $value; }

          if(isset($postText)){
          //echo $postText;
          $xml = new SimpleXMLElement($postText, LIBXML_NOCDATA);
          $record = $xml->record;
          // use first record to capture column names into array
          foreach($record[0]->record->children() as $col){
          $colNames[] = $col->getName();
          }

          // then for each column , record get the values
          foreach($record->record as $row){
          foreach($colNames as $column){
          $values[] = $row->$column;
          }
          //do something with the record
          }


          }
          else{
          exit;
          }




          //get record level element name;
          $act = $xml->act;
          $table = $xml->table;
          $record = $xml->records;

          // get column names