如何使用TYD3和extbase等标准字段,如crdate和cruser_id?

时间:2012-12-05 22:21:44

标签: model typo3 extbase

我有域模型篮子和文章。如果我打电话给以下人员,我会收到一揽子文章。

$articlesInBasket = $basket->getArticles();

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

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

3 个答案:

答案 0 :(得分:6)

首先,表格字段命名为crdatecruser,因此getter应命名为getCrdate并获取getCruser

接下来在你的模型中你需要添加一个字段和一个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    
        }
    }
}

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

答案 1 :(得分:6)

这适用于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

答案 2 :(得分:3)

这适用于TYPO3 8.7.13

模型:

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


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

TCA - >在colums中添加;

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

    ...

]
相关问题