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

koa*_*der 4 model typo3 extbase

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

$articlesInBasket = $basket->getArticles();
Run Code Online (Sandbox Code Playgroud)

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

$basket->getCrUser();
$basket->getCrDate();
Run Code Online (Sandbox Code Playgroud)

bie*_*ior 6

首先,表字段命名为crdate,cruser因此getter应该命名getCrdate并获取getCruser

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

/** @var int */
protected $crdate;

/**
* Returns the crdate
*
* @return int
*/
public function getCrdate() {
    return $this->crdate;
}
Run Code Online (Sandbox Code Playgroud)

(对cruser领域做同样的事)

最后,您setup.txt最需要为这些字段添加映射:

config.tx_extbase.persistence.classes {
    Tx_Someext_Domain_Model_Somemodel {
        mapping {
            columns.crdate.mapOnProperty = crdate
            columns.cruser.mapOnProperty = cruser    
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

  • crdate 不是字符串,而是 int(11) unsigned。因此它应该是 /** @var int */。 (2认同)

Urs*_*Urs 6

这适用于TYPO3 6.2.11

模型:

/**
 * tstamp
 *
 * @var int
 */
protected $tstamp;


/**
 * @return int $tstamp
 */
public function getTstamp() {
    return $this->tstamp;
}
Run Code Online (Sandbox Code Playgroud)

TS:

config.tx_extbase.persistence.classes {
    STUBR\Stellen\Domain\Model\Institution {
        mapping {
            tableName = tx_stellen_domain_model_institution
            columns {
                tstamp.mapOnProperty = tstamp
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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


web*_*Man 5

这在TYPO3 8.7.13中有效

模型:

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


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

TCA->将其添加到列中;

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

    ...

]
Run Code Online (Sandbox Code Playgroud)