I have an item with a referenced field to another app. A call has an assigned client.
I use this library: http://podio.github.io/podio-php/
I followed this article: http://podio.github.io/podio-php/fields/
I want to update an existing item by changing the item_id of its field that's referencing another app. The item_id already exists in the other app.
Here's what I tried (this happens when a Webhook is triggered):
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
AND
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array('item_id' => $id_client);
$item->save(array(
'hook' => false,
'silent' => true
));
Where 'client' is the external id of the field and $id_client is an integer number. Here's the error I get:
[18-Aug-2014 17:33:30 UTC] PHP Notice: Indirect modification of overloaded property PodioItem::$field has no effect in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
[18-Aug-2014 17:33:30 UTC] PHP Warning: Creating default object from empty value in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
If anyone could explain to me why this isn't working I'd be really grateful. The provided documentation is not clear on that subject.
Thank you!
SOLUTION
I got it to work this way, credits to Andreas:
if(!isset($item->fields['client']->values[0]->item_id)){
$item->fields['client'] = new PodioAppItemField();
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
}