7

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();
BenMorel
  • 34,448
  • 50
  • 182
  • 322
koalabruder
  • 2,794
  • 9
  • 33
  • 40

3 Answers3

17

This works in TYPO3 8.7 and 9.5

model:

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


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

TCA -> add this in the colums;

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

    ...

]
webman
  • 1,117
  • 15
  • 41
7

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

biesior
  • 55,576
  • 10
  • 125
  • 182
  • Thanks - crdate works. But I can't get the user behind cruser_id. Do you have an Example to map the cruser_id to a Domain Model? – koalabruder Dec 06 '12 at 10:49
  • 1
    you can use the mapping in ts to create a better variable name. Maybe you have to add a relation to the be_users table. – pgampe Dec 06 '12 at 17:59
  • 2
    crdate is not a string, but a int(11) unsigned. Therefore it should rather be /** @var int */. – Jonathan Gruber May 13 '15 at 08:02
  • I created a combination of your and webMans answer. The mapping was needed in my case which is why webMans solution didn't completely work out for me. Instead of an int one can use `\DateTime` as well. Works like a charm though! – Kathara Mar 09 '22 at 15:41
6

This works for me with TYPO3 6.2.11

model:

/**
 * 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 Thanks https://github.com/castiron/cicbase

Urs
  • 4,984
  • 7
  • 54
  • 116