TYPO3 扩展数据库域模型中的虚拟属性



我正在尝试在 TYPO3 9.5.x 中使用没有数据库字段表示形式的虚拟域模型属性,但我无法让它工作。

我的模型看起来像这样

class Project extends TYPO3CMSExtbaseDomainObjectAbstractEntity {
   /**
     * participants
     *
     * @var string
     */
    protected $participants;
    ...
    /**
     * Returns the participants
     *
     * @return string $participants
     */
    public function getParticipants()
    {
        $this->participants = "foo";
        return $this->participants;
    }
}

当我调试模型时,我确实看到了该属性,但它总是null好像它甚至无法识别 getter 方法getParticipants()

知道我可能做错了什么吗?

已经在ext_tables.sql和TCA中添加了一个数据库字段,但它似乎没有区别。

属性是null的,因为这是 Extbase 调试器检查它时的状态。请注意,Extbase 调试器对 getter 一无所知,也不会调用它们。

因此,如果要初始化属性,则必须在声明时执行此操作:

protected $participants = 'foo';

您可以通过简单地访问此属性来调试此属性。在 Fluid 中,如果您使用 <f:debug>{myModel}</f:debug> ,您将看到您的财产NULL

但是如果你直接使用<f:debug>{myModel.participants}</f:debug>,你会看到"foo"。

最新更新