2017-02-01 5 views
0

podio-phpを使用してAPI経由でフィールド値を設定しようとしています。Podio API:podio-phpラッパーを使って空のフィールドの値を設定する方法は?

$item = PodioItem::get_basic($item_id);  
$field = $item->fields["field-name"]; 
$field->values = "2"; // let's say we have a number filed 
$item->save(); // $field->save() also works 

をしかし、フィールドが空だった場合、警告Creating default object from empty valueは保存上のoccures:フィールドがすでに空でなかった場合、the manualに従って作られた次のスニペットは、正常に動作します。エラーは発生せず、アイテムに変更はありません。これは、さまざまなタイプのフィールドに当てはまります。私は、フィールドオブジェクトをゼロから作成する必要があると仮定しますが、異なるフィールドタイプに対してこれに関する情報を見つけることはできませんでした。

フィールドが空の場合、podio-phpで値を正しく設定する方法を教えてください。ありがとう。

答えて

0

単純な方法があるかもしれませんが、ここでは私が見つけた回避策があります。フィールドが空でない場合は、新しい値を割り当てます。しかし、フィールドが空の場合は、既存のフィールドと同じ名前の対応するタイプのフィールドオブジェクト(下のリストを参照)を作成し、それをフィールドコレクションに追加する必要があります。古い空のフィールドは新しいフィールドに置き換えられます。この例では

我々は数フィールドを設定します:他のフィールドの

$field_name = "field-name"; 
$new_value = 999; 

$item = PodioItem::get_basic($item_id); 
$field = $item->fields[$field_name]; 

if (count($field->values)){ // if the field is not empty 
    $field->values = $new_value; 
} else { // if the field is empty 
    $new_field = new PodioNumberItemField($field_name); // new field with the same(!) name 
    $new_field->values = $new_value; 
    $item->fields[] = $new_field; // the new field will replace the exsisting (empty) one 
} 

$item->save(); 

コンストラクタ(models/PodioItemField.phpで見つかった)タイプのオブジェクト:

PodioTextItemField 
PodioEmbedItemField 
PodioLocationItemField 
PodioDateItemField 
PodioContactItemField 
PodioAppItemField 
PodioCategoryItemField 
PodioImageItemField 
PodioFileItemField 
PodioNumberItemField 
PodioProgressItemField 
PodioDurationItemField 
PodioCalculationItemField 
PodioMoneyItemField 
PodioPhoneItemField 
PodioEmailItemField 
1

私は同じ問題を抱えていたし、この宝石を発見しました。

PodioItem::update(210606, array('fields' => array(
"title" => "The API documentation is much more funny", 
"business_value" => array('value' => 20000, "currency" => "EUR"), 
"due_date" => array('start' => "2011-05-06 11:27:20", "end" => "2012-04-30 
10:44:20"), 
)); 

個別のフィールドを更新できるように変更しました。しかし、これはその愚かなエラーなしでフィールドを更新します。

$FieldsArray = []; 
$FieldsArray['encounter-status'] = "Draft"; 
$item = PodioItem::update($itemID, array('fields' => $FieldsArray)); 
関連する問題