[TYPO3-mvc] How to set default values for a new Model object?
Sebastian Schreiber
me at schreibersebastian.de
Thu Jul 4 09:28:20 CEST 2013
Hi Martin,
in that case, i would declare the default value within the __constructor
of your Model.
public function __constructor() {
$this->lastChange = new DateTime();
}
The controller is in my opinion a bad place to set default values of a
model.
Just one note: time() will generate a unixtimestamp, but you declared
your property as a DateTime Object.
So i would recommend to assign a DateTime Object too =>
$this->lastChange = DateTime();
Am 03.07.2013 23:15, schrieb Martin Terber:
> Quote: Armin Rüdiger Vieweg wrote on Sat, 19 March 2011 12:30
> ----------------------------------------------------
>>
>> If possible I would set the default values for a model in its
>> attributes:
>>
>> class Tx_Extension_Domain_Model_Person extends
>> Tx_Extbase_DomainObject_AbstractEntity {
>> protected $firstname = 'John';
>> protected $name = 'Doe';
>> // ...
>> }
>>
> ----------------------------------------------------
>
> I don't fully understand. This doesn't work, obviously:
> [php]
> /**
> * Date of last change (from Frontend)
> *
> * @var DateTime
> */
> protected $lastChange = time();
> [/php]
>
> So I did this, after submitting data, before saving to db:
> [php]
> public function createAction(Tx_Extension_Domain_Model_Object $object) {
> $object->setLastChange(time());
> }
> [/php]
>
> Is that good practise?
>
--
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)
Schanzenstraße 27, Schlosserei 4
D-51063 Köln
T 0221 677 88 541
M 0176 431 05 790
Skype schreibersebastian.de
me at schreibersebastian.de
www.schreibersebastian.de
Steuernummer: 219 / 5302 / 3123
More information about the TYPO3-project-typo3v4mvc
mailing list