【问题标题】:How to set category field for new item with Podio PHP API如何使用 Podio PHP API 为新项目设置类别字段
【发布时间】:2015-04-10 14:22:06
【问题描述】:

我有一个由 php API 通过网站上的表单填充的 Podio 应用程序。

使用Create Item sn-p 适用于文本字段、货币值等,但我无法解开有关如何设置类别字段的文档。

类别字段“参加”是一个简单的是/否选择。

here 显示的方法在与 Create Item sn-p 结合使用时会产生服务器错误,如下所示:

$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();

我错过了什么?谢谢。

【问题讨论】:

    标签: php podio


    【解决方案1】:

    对于那些仍在寻找答案的人:诀窍是使用数组

    在打开集合之前执行 $attending 的评估,然后简单地 将此行添加到 PodioItemFieldCollection 中。

    new PodioCategoryItemField(array(
       'external_id' => 'attending', 'values' => array($attending))),
    

    所以整个 sn-p 应该是这样的

    ($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();
    

    【讨论】:

      【解决方案2】:

      您可以在以下位置找到示例:http://podio.github.io/podio-php/fields/#category-field

      如果仍然无法正常工作,请将 podio-php 置于调试模式,以便查看正在发送到 Podio 的数据:http://podio.github.io/podio-php/debug/

      【讨论】:

      • 谢谢安德烈亚斯,但那是我在问题中提到的我从中获取代码 sn-p 的页面。我的代码生成了内部服务器错误,因此没有可用的 Podio 调试信息。
      • 虽然这个答案可能有助于解决 OP 的问题,但最好提供一个完整的答案。
      猜你喜欢
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      相关资源
      最近更新 更多