How to use SOAP to get the class object and save file in a readable format.

124 views
Skip to first unread message

tapper

unread,
Jul 7, 2012, 11:02:11 PM7/7/12
to php-object...@googlegroups.com
[this group has been silent for awhile - but hopefully this will save someone some time...]

OK - I had one success and one is still a failure (failure is different post "How do you save SOAP GeneratePackage() results?").  But, I can live with the success, which is below

It took me a long time to figure out how to get the GenerateObject results into a readable, workable format.  When echo-ing the results to the screen and trying to save it, the format of the PHP file got looooossst big time.

Here's what worked for me. 

The key is the last step.  You save it to a file on your system.  That way the carriage returns and line feeds stay in tact and you get a readable, workable PHP file.
TIP: Make sure that

<?php

$wsdl = "http://www.phpobjectgenerator.com/services/soap_php5.php?wsdl";

$objectName = "user_signup";

$attributeList =array(
  "id_user_signup",
  "user_id",
  "user_email",
  "user_hash",
  "user_date_time_signup",
  "user_date_time_conf_email_sent",
  "user_date_time_conf_email_clicked"
  );

$typeList = array(           
  "int(11)",
  "int(11)",
  "varchar(120)",
  "varchar(180)",
  "datetime",
  "datetime",
  "datetime"
  );
           
$language = "php5";
$wrapper = "POG";
$pdoDriver = "mysql";

$soap_options = array(
                'soap_version'=>SOAP_1_2,
                'exceptions'=>true,
                'trace'=>1,
                'cache_wsdl'=>WSDL_CACHE_NONE
            );

try {

            //$client = new SoapClient($wsdl, $soap_options);
   
            $client = new SoapClient($wsdl);
            $results = base64_decode($client->GenerateObject(
                $objectName,
                $attributeList,
                $typeList,
                $language,
                $wrapper,
                $pdoDriver
            ));
        } catch (Exception $e) {
            echo "<h2>Exception Error!</h2>";
            echo $e->getMessage();
        }
      
//below - depending upon the server you are running this on, you might want to/need to put a path in front like below and change the permissions on the folder so your write succeeds.
//$filename = "/home/yourname/someplace/
class.".$objectName.".php";
$filename = "class.".$objectName.".php";
$fh = fopen($filename,'w');
fwrite($fh,$results);
echo 'Saved: '.$objectName;

?>



Reply all
Reply to author
Forward
0 new messages