微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Api Platform属性类型始终为STRING 考虑此属性:

如何解决Api Platform属性类型始终为STRING 考虑此属性:

尽管我努力进行类型提示public class TranscriptLogger : ITranscriptLogger { public IConfiguration _configuration; public TranscriptLogger(IConfiguration configuration) { _configuration = configuration; } public async Task LogActivityAsync(IActivity activity) { var isMessage = activity.AsMessageActivity() != null ? true : false; if (isMessage && !string.IsNullOrEmpty(activity.AsMessageActivity().Text)) { // saving conversation data } } } 批注,但Api Platform对此属性的解释始终是@var int

考虑此属性

string

我从Api平台获得了以下架构:


/**
 * @var int $geonameId The ID of a Geonames.org city/place/town
 *
 * @ORM\Column(type="bigint",options={"unsigned": true},nullable=true)
 * @Assert\Type(type="int",message="Geoname id must be an integer")
 */
protected $geonameId;

public function getGeonameId(): ?int
{
    return $this->geonameId;
}

public function setGeonameId(int $geonameId = null): self
{
    $this->geonameId = $geonameId;
    return $this;
}

当我尝试提交geonameId string nullable: true The ID of a Geonames.org city/place/town 时,出现以下错误

的“ geonameId”属性的类型必须为“ string”(指定为“ int”)之一。

我了解"geonameId": 123456注释以自定义属性等,但是当我已经使用类型提示和/或@var注释时,我不想冗长地定义类型以仅接受整数。

有人在我的所作所为中期望什么吗?预先感谢...

解决方法

像Doctrine一样将BIGINT映射为字符串。

参考: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html

bigint:将数据库BIGINT映射到PHP字符串的类型。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。