Filter items return value problem
My first steps working with the Podio API turns out to be a struggle to get items of an app out of Podio. I have found a possibly outdated but helpful example file with this in it:
`$item_collection = PodioItem::filter( YOUR_APP_ID );
// A collection is an associative array with some extra data in addition to the list of items.
print $item_collection['total']; // The total amount of items in the app
print $item_collection['filtered']; // Number of items matching the current filter
print_r($item_collection['items']); // Array of PodioItem instances`
but I found that 'total' and 'filtered' should be called as object properties ($item_collection->total and $item_collection->filtered). Unfortunately 'items' is not a property (anymore?) of the collection.
When I do a var_dump() of the $item_collection the first lines are:
object(PodioItemCollection)#340 (4) {
["filtered"]=>
int(116)
["total"]=>
int(116)
["__items":"PodioCollection":private]=>
array(20) {.....
and I don't have a clue how to get that result to show up in my PHP-page. Everything I need is in the array but it's in a private object.
Could you please point me to the part of the documentation where you explain how to get the actual result? I have read this https://developers.podio.com/doc/items/filter-items-4496747 and this https://developers.podio.com/doc/items/get-items-27803 .
Thank you so much!
-
Hi Sabine,
That is an old example you found. The current version of podio-php is a bit easier to work with. You can see a bit of documentation around collections at: http://podio.github.io/podio-php/objects/
But basically you can treat the collection as an array and just iterate over it:
$item_collection = PodioItem::filter( YOUR_APP_ID ) foreach ($item_collection as $item) { print "Item: " . $item->title; }
The documentation I link above also shows you how to use a
get
method to get items by their item_id and how to add and remove items from the collection. -
But thats only the value for the title, how do i get the email and category value etc?
$items = PodioItem::filter($app_id, $attributes = array(), $options = array());foreach ($items as $item) {$item_fields = $item->fields;// echo $item_fields[0] . "<br>";// echo $item_fields[1] . "<br>";// echo $item_fields[2] . "<br>";// echo $item_fields[3] . "<br><br><br>";foreach ($item_fields as $item_field) {echo $item_field->values . "<br><br>";}
}This is how far i got, but it only prints the title since its the only data not an array inside an array -
Lars
Notice: Array to string conversion in C:\xampp\htdocs\podio-test-api\app.php on line 26
Array
Notice: Array to string conversion in C:\xampp\htdocs\podio-test-api\app.php on line 26
Array
Asger
Notice: Array to string conversion in C:\xampp\htdocs\podio-test-api\app.php on line 26
Array
Array ( [0] => Array ( [file_id] => 1493494868 [link] => https://files.podio.com/1493494868 [thumbnail_link] => https://files.podio.com/1493494868 [hosted_by] => podio [name] => maxresdefault.jpg [mimetype] => image/jpeg [size] => 39632 ) )
Notice: Array to string conversion in C:\xampp\htdocs\podio-test-api\app.php on line 26
Array
Please sign in to leave a comment.
Comments
4 comments