【问题标题】:How to use standard fields like crdate and cruser_id with TYPO3 and extbase?如何在 TYPO3 和 extbase 中使用 crdate 和 cruser_id 等标准字段?
【发布时间】:2012-12-05 22:21:44
【问题描述】:

我有领域模型 Basket 和 Article。如果我拨打以下电话,我会收到篮子里的文章。

$articlesInBasket = $basket->getArticles();

如何使用 TYPO3 标准属性,例如 crdate 和 cruser_id。使用这样的东西会很好:

$basket->getCrUser();
$basket->getCrDate();

【问题讨论】:

  • Typo3 8.7.x 需要将该字段添加到模型的TCA中的列配置

标签: model typo3 extbase


【解决方案1】:

这适用于 TYPO3 8.7 和 9.5

型号:

/**
 * @var \DateTime
 */
protected $crdate = null;


/**
 * Returns the creation date
 *
 * @return \DateTime $crdate
 */
public function getCrdate()
{
    return $this->crdate;
}

TCA -> 将其添加到列中;

'columns' => [
    'crdate' => [
        'config' => [
            'type' => 'passthrough',
        ],
    ],

    ...

]

【讨论】:

    【解决方案2】:

    首先,表字段被命名为crdatecruser,所以getter应该命名为getCrdate和getgetCruser

    接下来您需要在模型中添加一个字段和一个 getter:

    /** @var int */
    protected $crdate;
    
    /**
    * Returns the crdate
    *
    * @return int
    */
    public function getCrdate() {
        return $this->crdate;
    }
    

    (对cruser字段做同样的事情)

    最后在setup.txt 中,您很可能需要为这些字段添加映射:

    config.tx_extbase.persistence.classes {
        Tx_Someext_Domain_Model_Somemodel {
            mapping {
                columns.crdate.mapOnProperty = crdate
                columns.cruser.mapOnProperty = cruser    
            }
        }
    }
    

    当然,不要忘记在设置中使用专有名称,并在代码更改后清除缓存

    【讨论】:

    • 谢谢 - crdate 有效。但我无法让 cruser_id 后面的用户。您是否有将 cruser_id 映射到域模型的示例?
    • 您可以使用 ts 中的映射来创建更好的变量名。也许您必须向 be_users 表添加一个关系。
    • crdate 不是一个字符串,而是一个无符号的 int(11)。因此它应该是 /** @var int */.
    • 我创建了您和 webMans 答案的组合。在我的情况下需要映射,这就是为什么 webMans 解决方案没有完全适合我的原因。也可以使用 \DateTime 而不是 int。工作就像一个魅力!
    【解决方案3】:

    这适用于我的 TYPO3 6.2.11

    型号:

    /**
     * tstamp
     *
     * @var int
     */
    protected $tstamp;
    
    
    /**
     * @return int $tstamp
     */
    public function getTstamp() {
        return $this->tstamp;
    }
    

    TS:

    config.tx_extbase.persistence.classes {
        STUBR\Stellen\Domain\Model\Institution {
            mapping {
                tableName = tx_stellen_domain_model_institution
                columns {
                    tstamp.mapOnProperty = tstamp
                }
            }
        }
    }
    

    PS 谢谢https://github.com/castiron/cicbase

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 1970-01-01
      相关资源
      最近更新 更多