Re: PHP array problem <ns4:item>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is the working code.... thanks again to Mike.

///////////////////////////////////////////
class messagesubmission {
    var $originator;            // originator
    var $recipient;             // recipient mobile number
    var $body;                  // text message
    var $type;                  // message type
    var $validityperiod;        // message type

    function messagesubmission ($aa) {
        foreach ($aa as $k=>$v)
            $this->$k = $aa[$k];
    }
}// end of class

class messageArray {

        var $entryList;

        function readDatabase($id_entity) {

                // Add MySQL query and loop to create array
                $message = array('originator' => 'originatno',
                                 'recipient' => 'recipno',
                                 'body' => 'This is a test message 1',
                                 'type' => 'Text',
                                 'validityperiod' => '10');

                $MessageObject = $this->createMessageObject($message);

                $this->add($MessageObject);
       }

        function createMessageObject($message) {
                return new messagesubmission($message);
        }

        function add($messageObject){
                $this->entryList[] = new
SOAP_Value("{namespace}messagesubmission", false,$messageObject);
        }
}

$messageArray = new messageArray();
$messageArray->readDatabase($id_entity);
$messages =  $messageArray->entryList;

//////////////////////////////////////////


"Mike Carter" <mikeatwork@ukonline.co.uk> wrote in message
11054A7BC9A71245BCBB9917579325730AF15F@mail.koa.uk.com">news:11054A7BC9A71245BCBB9917579325730AF15F@mail.koa.uk.com...
Hi,

That's nearly right (I think). The way I wrote my class was to have an add()
method. For each message object I created I would then call
->add($messageObj) to add the new message object to the array.

The adding to the array went along the lines of:-

$this->entryList[] = new SOAP_Value("{namespacegoeshere}Content", false,
$contentItem);

So rather than 'item' being put in front of each array element it puts
'Content' in there now.
$contentItem is the object passed in to the add() method.
'Namespacegoeshere' would be whatever namespace you use, ns4 I think is the
default alias?
$this->entryList; is declared in the class as an empty array, each call to
my add() method adds another message object to the array.

When I eventually cal lthe send method to call the webservice and send the
data I then do something along the lines of:-

$request = new stdclass;
$request->MemberId = $this->userId;
$request->CATCode = new
SOAP_Value("{{$GLOBALS['g_ps']['MedVisor']['serviceNamespace']}}ContentList"
, false, $this->entryList);

I've got an object containing an array of child objects then. Finally I pass
the $request object to the webservice call.
If you want to see the class in full I could email it privatly and you can
disect it properly?

Regards,



Mike C.


> -----Original Message-----
> From: Andrew Erskine [mailto:andy@merinet.com]
> Sent: 27 November 2003 14:09
> To: soap@lists.php.net
> Subject: Re:  PHP array problem <ns4:item>
>
>
> I've created an object for each message and then created an
> array of these
> objects. Unfortunately we still get the same problem as the
> PEAR library
> forces an <item> tag if the array key is either blank or
> numeric.  I'm not
> sure whether I understood Mikes suggestion.........
>
> My code snippet is
>
> //////////////////////////////////////////////////////////////
> //////////////
> //////////////////////////////////
>
> class messagesubmission {
>     var $originator;            // originator mobile number
>     var $recipient;             // recipient mobile number
>     var $body;                  // text message
>     var $type;                  // message type
>     var $validityperiod;        // message type
>
>     function messagesubmission ($aa) {
>         foreach ($aa as $k=>$v)
>             $this->$k = $aa[$k];
>     }
> }// end of class
>
>
>     function readMessage() {
>
>     // create message 1
>     $message = array('originator' => 'originatorno',
>                      'recipient' => 'recipentno',
>                      'body' => 'This is a test message 1',
>                      'type' => 'Text',
>                       'validityperiod' => '10');
>
>     $MyObjectArray[][messagesubmission] =
> createMessageObject($message);
>
>     // create message 2
>    $message = array('originator' => 'originatorno',
>                      'recipient' =>  'recipentno',
>                      'body' => 'This is a test message 2',
>                      'type' => 'Text',
>        'validityperiod' => '10');
>
>     $MyObjectArray[][messagesubmission] =
> createMessageObject($message);
>
>     return $MyObjectArray;
> }
>
> function createMessageObject($message) {
>     return new messagesubmission($message);
> }
>
> $messages = readMessage();
>
> //////////////////////////////////////////////////////////////
> //////////////
> //////////////////////////////////
>
> Any help would be very welcome.
>
> Andy E
>
>
> "Mike Carter" <mikeatwork@ukonline.co.uk> wrote in message
> 11054A7BC9A71245BCBB991757932573100FE6@mail.koa.uk.com">news:11054A7BC9A71245BCBB991757932573100FE6@mail.koa.uk.com...
> >
> >
> > > -----Original Message-----
> > > From: Thomas Ashbee [mailto:thomas@merinet.com]
> > > Sent: 25 November 2003 13:06
> > > To: soap@lists.php.net
> > > Subject:  PHP array problem <ns4:item>
> > >
> > > How do i stop the <ns4:item> being inserted in to the request
> > >
> > >
> > > $message_array = array(
> > >                             array('originator' => 'originatorno',
> > >                                   'recipient' => 'recipentno',
> > >                                   'body' => 'This is a
> test message',
> > >                                   'type' => 'Text',
> > >           'validityperiod' => '10'),
> > >             array('originator' => 'originatorno',
> > >                                   'recipient' => 'recipentno',
> > >                                   'body' => 'This is a
> test message',
> > >                                   'type' => 'Text',
> > >           'validityperiod' => '10')
> > >           );
> > >
> > > $secondarray = array('messagesubmission' => $message_array);
> > >
> >
> > Use objects rather than nested arrays to put your
> attributes in. I use a
> > stdClass like:
> > $req = new StdClass;
> > $req->originator = 'originatorno';
> > $req->recipient = 'recipentno';
> > Etc...
> > Then add this class to the parent class (if your nesting
> things) before
> > submitting it to the webservice.
> >
> > Regards,
> >
> >
> >
> > Mike C.
> >
> >
> >
> ______________________________________________________________
> __________
> > This email has been scanned for all viruses by the MessageLabs Email
> > Security System. For more information on a proactive email security
> > service working around the clock, around the globe, visit
> > http://www.messagelabs.com
> >
> ______________________________________________________________
> __________
>
> -- 
> PHP Soap Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

-- 
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Kernel Newbies]     [PHP Database]     [Yosemite]

  Powered by Linux