Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting value of particular array-key(protected) from response object? #3

Closed
khurshid-alam opened this issue May 22, 2014 · 3 comments

Comments

@khurshid-alam
Copy link

This is the sample code I used....to get a particular task list:

$tasks = $rtm->getService(Rtm::SERVICE_TASKS);
$response = $tasks->getList("status:incomplete AND tag:work", 16594223, NULL, NULL);

print_r($response);

And this the sample response I am getting:


Rtm\DataContainer Object
(
    [attributes:Rtm\DataContainer:private] => Array
        (
            [0] => Rtm\DataContainer Object
                (
                    [attributes:Rtm\DataContainer:private] => Array
                        (
                            [id] => 19594773
                            [taskseries] => Rtm\DataContainer Object
                                (
                                    [attributes:Rtm\DataContainer:private] => Array
                                        (
                                            [id] => 310899576
                                            [created] => 2013-10-03T05:35:52Z
                                            [modified] => 2013-11-06T17:24:36Z
                                            [name] => A new task
                                            [source] => js
                                            [url] => 
                                            [location_id] =>

                                        )
                                )
                        )
              )
      )
)

I want to extract the value of [name]. How can I do it? $response->getTaskSeries()->getName() does not work.

I guess this type of serialization has already been implemented inside the class.

@khurshid-alam khurshid-alam changed the title Getting value of particular field from response object? Getting value of particular array-key(protected) from response object? May 22, 2014
@bartosz-maciaszek
Copy link
Owner

In this case "$response" contains a collection (array), so you just need to traverse it using foreach:

foreach ($response as $item) {
    // Get the name with: $item->getTaskseries()->getName();
}

@khurshid-alam
Copy link
Author

Thanks.That worked. But in real response object, I can get taskseries just fine but can't get name at single go without using another foreach like this:

foreach ($response as $item) {
    $ts = $item->getTaskseries();
    foreach ($ts as $item2) {
        $name[] = $item2->getName();
    }
}
print_r($name[0]);

@bartosz-maciaszek
Copy link
Owner

Yeah, you can be right here. It all depends on the structure of data returned by Remember The Milk API. This library just wraps the response with an object. For more info on the data structure, please refer to the RTM API methods documentation (https://www.rememberthemilk.com/services/api/methods/).

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants