【问题标题】:Problem creating an instance of ObjectStorage创建 ObjectStorage 实例的问题
【发布时间】:2020-05-09 19:38:47
【问题描述】:

在我的域模型中有一个属性month,它是ObjectStoragebill 元素。以下是域模型的外观:

    /**
     * establishment
     *
     * @var ObjectStorage<Bill>
     * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
     */
    protected ObjectStorage $month;

    public function __construct()
    {
        $this->setMonth(new ObjectStorage());
    }

这里是二传手:

    /**
     * month setter
     *
     * @param ObjectStorage<Bill> $month
     * @return void
     */
    public function setMonth(ObjectStorage $month) : void
    {
        $this->month = $month;
    }

遗憾的是phpstan 显示以下错误:

参数 #1 $建立方法 VIC\Ext\Domain\Model\StorageRoom::setMonth() 需要 iterable&TYPO3\CMS\Extbase\Persistence\ObjectStorage,
给定的 TYPO3\CMS\Extbase\Persistence\ObjectStorage。

知道有什么问题吗?

【问题讨论】:

  • 您应该将提到的设置器添加到您的代码摘录中。此外,如果您将 ObjectStorage 属性正确映射到数据库字段,则无需初始化它们。
  • 嗨,它们似乎在 TCA 中正确映射
  • Foreign_table = Bill Foreign_field = StorageRoom 似乎是正确的。无论如何感谢您的提示

标签: typo3 extbase phpstan typo3-10.x


【解决方案1】:

如何构建 phpstan 的构造:

/** * 成立 * * @var ObjectStorage * @TYPO3\CMS\Extbase\Annotation\ORM\Cascade("删除") */ 受保护的$月; 公共函数 __construct() { /** @var ObjectStorage $objectStorageBill */ $objectStorageBill = 新的 ObjectStorage(); $this->setMonth($objectStorageBill); }

【讨论】:

    猜你喜欢
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多