0

我正在像这样使用 updateSingleValue:

$updated = $this->app['storage']->updateSingleValue('suggestions', $id, 'votes', $value);

$idand$value设置正确(即使我手动将它们设置为更正整数),并且肯定存在带有suggestions字段votes的内容类型。然而,这个函数返回false,表明!$this->isValidColumn($field, $contenttype)失败。

一个suggestionjson 格式的文件如下所示:

suggestion": {
"id": "25",
"values": {
    "datechanged": "2015-01-03 13:25:02",
    "id": "25",
    "slug": "slug-o2sbdb",
    "datecreated": "2015-01-03 13:25:02",
    "datepublish": "2015-01-03 13:25:02",
    "datedepublish": "1900-01-01 00:00:00",
    "ownerid": "1",
    "status": "published",
    "title": "test title",
    "description": "test description",
    "votes": "0"
},

建议内容类型如下所示:

suggestions:
    name: Suggestions
    slug: suggestions
    singular_name: Suggestion
    singular_slug: suggestion
    default_status: publish
    fields:
        title:
            label: Title
            type: text
            class: large
            required: true
            pattern: ".{2,255}" # see: http://html5pattern.com/
            error: "The Title field is required, and must contain at least 2 characters"
        description:
            label: Description
            type: textarea
        votes:
            label: Votes
            type: integer

我在这里做错了什么?

4

1 回答 1

0

在这里发现了问题,传递给 updateSingleValue 的内容类型需要是整个内容类型,而不仅仅是 slug 的“建议”。您可以通过存储类方法获取它:

$app['storage']->getContentType('suggestions')

然后将结果传递给 updateSingleValue 方法。

于 2015-01-04T06:16:23.237 回答