Using PodioObject & PodioCollection
If you are manipulating items from Podio apps be sure to read Podio items as well.
Most API calls return a Podio object that matches the class you called a static method on or a PodioCollection of those objects. E.g. PodioSearchResult::app()
will return a PodioCollection containing PodioSearchResult objects. PodioItem::get()
will return a single PodioItem object.
Once you have a Podio* object you might be tempted to simply var_dump
it to see which properties are available. This would be a mistake. Due to the dynamic nature of the data structures returned from the Podio API Podio* objects use magic getters and setters. With a var_dump
you will just see the internal data structure which is cumbersome to work with.
To see which properties you can access on an object type open the class file and look at the constructor. The class files are all located in the models folder. As an example look at PodioTask. You can see three methods being called to setup the properties:
$this->property()
declares a normal property.$this->has_one()
declares a one-to-one relationship to another Podio* object. E.g. PodioTask has a propertycreated_by
which contains a singlePodioByLine
object.$this->has_many()
declares a one-to-many relationship to another Podio* object. E.g. PodioTask has a propertycomments
which contains an array ofPodioComment
objects.
Alternatively, create an object and call properties
and relationships
methods:
You can access all attributes directly on your objects even though they are not declared as normal class properties would be. E.g. when working with a task:
In a similar fashion you change values simply by assigning them. Changes are not automatically saved to the API. You must manually save them yourself.
Additionally, Podio* objects have a few functions that can make your life easier.
PodioCollection
A PodioCollection is as the name implies a collection of Podio* objects. They behave in most ways the same way an array would. You can iterate over it and add/remove objects in the same way you would for arrays.