[英]How to set category field for new item with Podio PHP API
I have a Podio app which is populated by the php API via a form on a website. 我有一个Podio应用,该应用由php API通过网站上的表格填充。
Using the Create Item snippet works for text fields, currency values, etc but have been I unable to untangle the documentation as to how to set a category field. 使用“ 创建项目”代码段可用于文本字段,货币值等,但是我无法解开有关如何设置类别字段的文档。
The category field, "attending", is a simple yes/no choice. 类别字段“出席”是一个简单的是/否选择。
The method shown here generates a server error when combined with Create Item snippet as below: 当与创建项目代码段结合使用时, 此处显示的方法将产生服务器错误,如下所示:
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "title", "values" => $name)),
new PodioTextItemField(array("external_id" => "email", "values" => $email)),
));
$item = new PodioItem(array(
'app' => new PodioApp(intval($app_id)),
'fields' => $fields,
));
pseudo code: if attending = yes, $attending = 1, else $attending = 2 //id's of yes and no in category field
$item->fields['attending']->values = $attending;
$item->save();
What am I missing? 我想念什么? Thanks.
谢谢。
For those still searching for an answer: The trick is to use an array . 对于仍在寻找答案的人: 诀窍是使用array 。
Perform the evaluation of $attending before opening the Collection and then simply add this line into the PodioItemFieldCollection . 在打开Collection之前执行$ attending的求值,然后只需将此行添加到PodioItemFieldCollection中 。
new PodioCategoryItemField(array(
'external_id' => 'attending', 'values' => array($attending))),
So the whole snippet would look like this 所以整个代码段看起来像这样
($foo == 'yes') ? $attending = 1: $attending = 2 ; // evaluating $foo for yes
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "title", "values" => $name)),
new PodioTextItemField(array("external_id" => "email", "values" => $email)),
new PodioCategoryItemField(array(
'external_id' => 'attending', 'values' => array($attending))) // must be an array
));
$item = new PodioItem(array(
'app' => new PodioApp(intval($app_id)),
'fields' => $fields,
));
$item->save();
You can find examples at: http://podio.github.io/podio-php/fields/#category-field 您可以在以下位置找到示例: http : //podio.github.io/podio-php/fields/#category-field
If it's still not working, place podio-php into debug mode so you can see what data is being sent to Podio: http://podio.github.io/podio-php/debug/ 如果仍然无法正常工作,请将podio-php置于调试模式,这样您就可以查看将什么数据发送到Podio: http ://podio.github.io/podio-php/debug/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.