Extbase - Timestamp nutzen: Unterschied zwischen den Versionen
(Die Seite wurde neu angelegt: „<syntaxhighlight lang="typoscript"> $TCA['tx_myext_domain_model_mymodel']['columns']['crdate'] = Array ( 'exclude' => 1, 'label' => 'Cr…“) |
|||
| (4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| + | == Beispiele == | ||
| + | === Beispiel crdate und tstamp nutzen === | ||
| + | http://stackoverflow.com/questions/13733546/how-to-use-standard-fields-like-crdate-and-cruser-id-with-typo3-and-extbase (2015-06) | ||
| + | |||
| + | The table fields are named as crdate, and cruser so getters should be named getCrdate and get getCruser. In your model you need to add a field and a getter: | ||
| + | <syntaxhighlight lang="php"> | ||
| + | /** | ||
| + | * crdate | ||
| + | * @var int | ||
| + | */ | ||
| + | protected $crdate; | ||
| + | |||
| + | /** | ||
| + | * Returns the crdate | ||
| + | * | ||
| + | * @return int | ||
| + | */ | ||
| + | public function getCrdate() { | ||
| + | return $this->crdate; | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | (do the same with cruser field) | ||
| + | |||
| + | And finally in you setup.txt most probably you'll need to add a '''mappings for these fields''': | ||
| + | <syntaxhighlight lang="typoscript"> | ||
| + | config.tx_extbase { | ||
| + | persistence { | ||
| + | classes { | ||
| + | Vendor\MyPackage\Domain\Model\Modelname { | ||
| + | mapping { | ||
| + | columns { | ||
| + | tstamp.mapOnProperty = tstamp | ||
| + | hidden.mapOnProperty = hidden | ||
| + | crdate.mapOnProperty = crdate | ||
| + | cruser_id.mapOnProperty = cruserId | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | === Beispiel === | ||
| + | |||
| + | Evtl. könnte man das TCA mit den Standardwerten die Typo3 nutzt zu überschreiben oder sogar diese kopieren. Wenn man nur wüßte wo die sind :-) | ||
| + | |||
<syntaxhighlight lang="typoscript"> | <syntaxhighlight lang="typoscript"> | ||
$TCA['tx_myext_domain_model_mymodel']['columns']['crdate'] = Array ( | $TCA['tx_myext_domain_model_mymodel']['columns']['crdate'] = Array ( | ||
| Zeile 9: | Zeile 56: | ||
)); | )); | ||
| + | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Aktuelle Version vom 26. Juni 2015, 18:11 Uhr
Beispiele[Bearbeiten]
Beispiel crdate und tstamp nutzen[Bearbeiten]
The table fields are named as crdate, and cruser so getters should be named getCrdate and get getCruser. In your model you need to add a field and a getter:
/**
* crdate
* @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 {
Vendor\MyPackage\Domain\Model\Modelname {
mapping {
columns {
tstamp.mapOnProperty = tstamp
hidden.mapOnProperty = hidden
crdate.mapOnProperty = crdate
cruser_id.mapOnProperty = cruserId
}
}
}
}
}
}
Beispiel[Bearbeiten]
Evtl. könnte man das TCA mit den Standardwerten die Typo3 nutzt zu überschreiben oder sogar diese kopieren. Wenn man nur wüßte wo die sind :-)
$TCA['tx_myext_domain_model_mymodel']['columns']['crdate'] = Array (
'exclude' => 1,
'label' => 'Creation date',
'config' => Array (
'type' => 'none',
'format' => 'date',
'eval' => 'date',
));
);
das model erweitern um ein DateTime property und entsprechende getter und setter methoden.
/**
* crdate
*
* @var string
*/
protected $crdate;
/**
* Returns the crdate
*
* @return string $crdate
*/
public function getCrdate() {
return $this->crdate;
}
/**
* Sets the crdate
*
* @param string $crdate
* @return void
*/
public function setCrdate($crdate) {
$this->crdate = $crdate;
}
ausschlaggebend ist zuerst das tca. was dort nicht enthalten ist, wird auch nicht in das model gemappt.
So lässt sich das Datum in Fluid noch ordentlich formatiert ausgeben:
<f:format.date format="d.m.Y - H:i">{firma.tstamp}</f:format.date> Uhr
Vorsicht - scheinbar nutzt der View Helper immer gmt. D.h. die Uhr geht 1h falsch bei uns.