【问题标题】:Repeating elements in an array for a php soap call为 php soap 调用重复数组中的元素
【发布时间】:2011-12-15 23:18:53
【问题描述】:

我正在进行一个soap调用,但是其中一个嵌套元素重复,所以当我创建数组时它被覆盖,对元素进行编号以响应soap请求。

 $result = $client->SaveEventRegistration(array(

    'SetEventRegistrationRQ' => array(

        'Attendees' => array( 
            'Attendee' => array(
                'EventRegistrationTypeID' => '3125',
                'NoofSeats' => '2',
                'RegistrationCost' => '20',
                'Contact' => array(
                    'FirstName' => 'Danny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                ),
                'Attendee' => array(
                'EventRegistrationTypeID' => '3149',
                'NoofSeats' => '2',
                'RegistrationCost' => '30',
                'Contact' => array(
                    'FirstName' => 'Penny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                )
            ),
        'EventId' => '2652',
        'RegistrationBy' => array(
            'FirstName' => 'Incredible',
            'LastName' => 'Hulk',
            'Email' => 'hulk@domain.co.nz',
            'EventScheduleId' => '2617'
        )
        )));

【问题讨论】:

  • 这些元素中有哪些重复(以及在哪里)?

标签: php soap


【解决方案1】:

在我的朋友(和Passing a PHP array in a SOAP call)的帮助下,我找到了解决方案。主要问题是 php 用第二次出现覆盖了参加者变量。我必须找到一种方法来存储与会者的两个元素。以为我会在这里发布,因为它与其他问题略有不同。

    // turn $attendee into an array (I think it's non-associative?)
      $attendee = array();
   // create the elements that repeat. Note the name of the array becomes part of the soap call so must be the right parameter you intend to send in the SOAP call.
      $attendee[] = array(
                    'EventRegistrationTypeID' => '3125',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Danny',
                        'LastName' => 'Hulk',
                        'Email' => 'Danny@domain.co.nz',
                        'IsForNewsletter' => 'true'
                        ));
$attendee[] = array(
                    'EventRegistrationTypeID' => '3149',
                    'NoofSeats' => '2',
                    'RegistrationCost' => '20',
                    'Contact' => array(
                        'FirstName' => 'Penny',
                        'LastName' => 'Hulk',
                        'Email' => 'Penny@domain.co.nz',
                        'IsForNewsletter' => 'true'
                        ));


 // make the SOAP call ($client defined elsewhere). Insert the array created above in the appropriate place inside the correct tag (Attendees in my case).  

$result = $client->SaveEventRegistration(array(

        'SetEventRegistrationRQ' => array(

            'Attendees' => $attendee,
            'EventId' => '2652',
            'RegistrationBy' => array(
                'FirstName' => 'Incredible',
                'LastName' => 'Hulk',
                'Email' => 'hulk@domain.co.nz',
                'EventScheduleId' => '2617'
            ))));

【讨论】:

    【解决方案2】:

    如果你不明确地为重复的项目编号会发生什么?

    $result = $client->SaveEventRegistration(array(
    
    'SetEventRegistrationRQ' => array(
    
        'Attendees' => array( 
    
            array(
                'EventRegistrationTypeID' => '3125',
                'NoofSeats' => '2',
                'RegistrationCost' => '20',
                'Contact' => array(
                    'FirstName' => 'Danny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                ),
            array(
                'EventRegistrationTypeID' => '3149',
                'NoofSeats' => '2',
                'RegistrationCost' => '30',
                'Contact' => array(
                    'FirstName' => 'Penny',
                    'LastName' => 'Hulk',
                    'Email' => 'hulk@domain.co.nz',
                    'IsForNewsletter' => 'true'
                    )
                )
            ),
        'EventId' => '2652',
        'RegistrationBy' => array(
            'FirstName' => 'Incredible',
            'LastName' => 'Hulk',
            'Email' => 'hulk@domain.co.nz',
            'EventScheduleId' => '2617'
        )
        )));
    

    我想你应该看看这个类似的问题:PHP repeated elements in a soap call

    【讨论】:

      猜你喜欢
      • 2011-04-18
      • 1970-01-01
      • 2014-04-01
      • 2012-11-04
      • 2011-06-22
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多