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

3

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();
Parasang answered 5/12, 2012 at 22:21 Comment(1)
Typo3 8.7.x you need to add the field to the column configuration in the model's TCABarthel
T
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

Tavel answered 6/12, 2012 at 1:1 Comment(4)
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?Parasang
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.Widera
crdate is not a string, but a int(11) unsigned. Therefore it should rather be /** @var int */.Elena
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!Enlist
H
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',
        ],
    ],

    ...

]
Hairspring answered 3/6, 2018 at 3:25 Comment(0)
T
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

Tavel answered 6/12, 2012 at 1:1 Comment(4)
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?Parasang
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.Widera
crdate is not a string, but a int(11) unsigned. Therefore it should rather be /** @var int */.Elena
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!Enlist
B
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

Bob answered 1/4, 2015 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.