肥皂如何只返回想要的结果?

时间:2014-04-29 15:59:33

标签: php arrays soap

好的,我使用php soap调用API,返回一个数组,但我希望能够指定我想要返回的内容... 让我添加一些代码看看它更有意义: 确定这会调用返回我的数组的服务:

 class MBClassService extends MBAPIService
    {   
        public function GetClassDescriptions(array $classDescriptionIDs, array $staffIDs, array $locationIDs, $startTime, $endTime, $PageSize = NULL, $CurrentPage = NULL, $XMLDetail = XMLDetail::Full, $Fields = NULL, SourceCredentials $credentials = null)
        {
            $additions = array();
            if (count($classDescriptionIDs) > 0){
                $additions['ClassDescriptionsIDs'] = $classDescriptionIDs;
                var_dump($additions['ClassDescriptionsIDs']);
            }
            if (count($staffIDs) > 0)
            {
                $additions['StaffIDs'] = $staffIDs;
            }
            if (count($locationIDs) > 0)
            {
                $additions['LocationIDs'] = $locationIDs;
            }
            if (isset($startDate))
            {
                $additions['StartClassDateTime'] = $startDate->format(DateTime::ATOM);
            }
            if (isset($endDate))
            {
                $additions['EndClassDateTime'] = $endDate->format(DateTime::ATOM);
            }

        $params = $this->GetMindbodyParams($additions, $this->GetCredentials($credentials), $XMLDetail, $PageSize, $CurrentPage, $Fields);

        try
        {
            $result = $this->client->GetClassDescriptions($params);
        }
        catch (SoapFault $fault)
        {
            DebugResponse($result);
            echo '</xmp><br/><br/> Error Message : <br/>', $fault->getMessage(); 
        }

        if ($this->debug)
        {
            DebugRequest($this->client);
            DebugResponse($this->client, $result);
        }

        return $result;
        }
}

我这样称呼它:

$resultTest = $classService->GetClassDescriptions(array(502, 4, 5), array(), array(), null, null, 150, 0);

但无论我在GetClassDescription中添加第一个数组,它总是会返回所有结果... 这是$ resultTest的var转储示例:

object(stdClass)#1023 (1) {
  ["GetClassDescriptionsResult"]=>
  object(stdClass)#1024 (7) {
    ["Status"]=>
    string(7) "Success"
    ["ErrorCode"]=>
    int(200)
    ["XMLDetail"]=>
    string(4) "Full"
    ["ResultCount"]=>
    int(132)
    ["CurrentPageIndex"]=>
    int(0)
    ["TotalPageCount"]=>
    int(1)
    ["ClassDescriptions"]=>
    object(stdClass)#1025 (1) {
      ["ClassDescription"]=>
      array(132) {
        [0]=>
        object(stdClass)#1026 (9) {
          ["Level"]=>
          object(stdClass)#1027 (2) {
            ["ID"]=>
            int(1)
            ["Name"]=>
            string(17) "Beginner"
          }
          ["ID"]=>
          int(1)
          ["Name"]=>
          string(23) "Salsa - Beginner/Novice"
          ["Description"]=>
          string(47) "Learn fun and easy basics for Salsa."
          ["Prereq"]=>
          string(37) "No prior lessons required."
          ["Notes"]=>
          string(0) ""
          ["LastUpdated"]=>
          string(22) "2012-11-30T18:57:29.91"
          ["Program"]=>
          object(stdClass)#1028 (3) {
            ["ID"]=>
            int(22)
            ["Name"]=>
            string(13) "Group Classes"
            ["ScheduleType"]=>
            string(6) "DropIn"
          }
          ["SessionType"]=>
          object(stdClass)#1029 (4) {
            ["DefaultTimeLength"]=>
            NULL
            ["ProgramID"]=>
            int(22)
            ["ID"]=>
            int(6)
            ["Name"]=>
            string(19) "Social Group Lesson"
          }
        }
        [1]=>
        object(stdClass)#1030 (9) {
          ["Level"]=>
          object(stdClass)#1031 (2) {
            ["ID"]=>
            int(1)
            ["Name"]=>
            string(17) "Absolute Beginner"
          }
          ["ID"]=>
          int(2)
          ["Name"]=>
          string(26) "Two Step - Beginner/Novice"
          ["Description"]=>
          string(51) "Learn fun & easy basics for Two Step"
          ["Prereq"]=>
          string(37) "No prior lessons required."
          ["Notes"]=>
          string(0) ""
          ["LastUpdated"]=>
          string(22) "2012-11-30T19:02:40.29"
          ["Program"]=>
          object(stdClass)#1032 (3) {
            ["ID"]=>
            int(22)
            ["Name"]=>
            string(13) "Group Classes"
            ["ScheduleType"]=>
            string(6) "DropIn"
          }
          ["SessionType"]=>
          object(stdClass)#1033 (4) {
            ["DefaultTimeLength"]=>
            NULL
            ["ProgramID"]=>
            int(22)
            ["ID"]=>
            int(6)
            ["Name"]=>
            string(19) "Social Group Lesson"
          }
          }
        }
      }
    }
  }
}

那么我如何只返回想要的结果说:

["Level"]=> object(stdClass)#1031 (2) {["ID"]=>int(1) ["Name"]=> string(17) "Absolute Beginner"

仅? 我想我可以在他们被重新审理之后遍历结果,这似乎是一种回归我不需要的东西...... 克里斯

1 个答案:

答案 0 :(得分:1)

我认为这取决于API的结构。无论API的回报是什么,这都是你必须要处理的。你真的要解析。