How to use standard fields like crdate and cruser_id with TYPO3 and extbase?

extbase, model, typo3

Solution

First, the table fields are named as `crdate`, and `cruser` so getters should be named `getCrdate` and get `getCruser`

Next in your model you need to add a field and a getter:

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

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

(do the same with `cruser` field)

And finally in you `setup.txt` most probably you'll need to add a mappings for these fields:

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

Of course, don't forget to use proper names in the settings, and clear the cache after changes in the code

Problem

I have the domain models Basket and Article. If I call the following I receive the articles in the basket. ``` $articlesInBasket = $basket->getArticles(); ``` How can I use the TYPO3 standard attributes like crdate and cruser_id. It would be nice to use something like this: ``` $basket->getCrUser(); $basket->getCrDate(); ```

Original source