Example on best practise with items->getValue() or getfieldvalue()
AnsweredHello everybody,
I am not a professional programmer - so please forgive me for asking basics :)
I am working with the API (php client) and I am trying to find the best way how to get the current values from an item. I am having real difficulties working with the returned array from the getValue() or getfieldvalue() function. Right now I am basically doing everything manually just to get to the values of an item.
So you better understand my dilemma - here is my approach right now:
$pvalues = array();
$pvalues['vorname'] = $podioapi->item->getfieldvalue(item_id,field_id); _
_$pvalues['nachname'] = $podioapi->item->getfieldvalue(item_id,field_id);
_ $pvalues['anrede'] = $podioapi->item->getfieldvalue(item_id,field_id);_
_ $pvalues['title'] = $podioapi->item->getfieldvalue(item_id,field_id);_
_ $pvalues['email'] = $podioapi->item->getfieldvalue(item_id,field_id); _
$pvalues['status'] = $podioapi->item->getfieldvalue(item_id,field_id);
_ $pvalues['sprache'] = $podioapi->item->getfieldvalue(item_id,field_id); _
$pvalues['anmeldung'] = $podioapi->item->getfieldvalue(item_id,field_id);
_ $pvalues['letztes-update'] = $podioapi->item->getfieldvalue(item_id,field_id);_
Checking the output - accessing the actual field values:
echo $pvalues['vorname'][0]['value']."<br/>"; _
_echo $pvalues['nachname'][0]['value']."<br/>"; _
_echo $pvalues['anrede'][0]['value']."<br/>"; _
_echo $pvalues['title'][0]['value']."<br/>"; _
_echo $pvalues['email'][0]['value']."<br/>";
_ echo $pvalues['status'][0]['value']['id']."<br/>"; _
echo $pvalues['sprache'][0]['start']."<br/>";
There has to be a faster and easier way right?
Maybe you can give me a hint on how to approach this in an php environment!!
Thank you so much for the help!
Michael
-
Hi Michael,
I must urge you to seek out some general PHP tutorials if you do not have much experience with programming. Otherwise you will have trouble every step of the way. At the very least you need to be comfortable working with arrays.
For this question: It's not convenient to fetch each value individually. You should get the entire item using:
$item = $api->item->get($item_id);
Then you can loop over all the fields in $item['fields']
Please sign in to leave a comment.
Comments
4 comments