updateSingleValue() returns false,但输入正确

updateSingleValue() returns false, yet inputs are correct

我正在这样使用 updateSingleValue:

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

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

suggestion json 格式如下所示:

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

我在这里做错了什么?

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

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

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