[FLOW3-general] Storing default values or properties into database

Ed Nkongme pss93 at gmx.de
Fri Nov 11 15:52:12 CET 2011


Am 11.11.11 13:46, schrieb "Christian Müller (Kitsunet)":
> On 11/11/11 12:48, Nkongme wrote:
>> Hi guys,
>>
>> I would like to use the model below to automatically store a timestamp
>> into the database when a user object is created and persisted. When I
>> use the code below, the property/field "registrationdate" is always
>> stored with the value 0000-00-00 00:00:00 and not the actual date. What
>> am I doing wrong?
>
> Hi,
>
> first (but I don't think that is the problem) you can drop
> "@ORM\Column(type="datetime")" as this is determined by the @var
> annotation normally.
>
> Now how do you create your User object? Lets say you have your action
> and you simply do:
>
> $newUser = new \I\Dont\Know\The\NameSpace\User();
> $userRepository->add($newUser);
>
> Then registrationdate should be set correctly (you should add a getter
> for it), and it should also be persisted like that.
>
> More info would be good to look into it, probably just a minor thing. In
> fact the FLOW security Account model does just the same thing...
>
> Cheers,
> Christian
>
>
>>
>> use Doctrine\ORM\Mapping as ORM;
>> use TYPO3\FLOW3\Annotations as FLOW3;
>>
>> /**
>> * A User
>> *
>> * @FLOW3\Scope prototype
>> * @FLOW3\Entity
>> */
>> class User {
>>
>> /**
>> * The name
>> * @var string
>> */
>> protected $name;
>>
>> /**
>> * @var \DateTime
>> * @ORM\Column(type="datetime")
>> */
>> protected $registrationdate;
>>
>> /**
>> * Constructs this user
>> */
>> public function __construct() {
>> $this->registrationdate = new \DateTime();
>> }
>>
>> /**
>> * Get the User's name
>> *
>> * @return string The User's name
>> */
>> public function getName() {
>> return $this->name;
>> }
>>
>> /**
>> * Sets this User's name
>> *
>> * @param string $name The User's name
>> * @return void
>> */
>> public function setName($name) {
>> $this->name = $name;
>> }
>>
>> }
>>
>> I would appreciate any suggestions. Thanks!
>> Ed
>

Hi Christian,
Thanks for your reply. My code above just worked. I had to do 
flow3:cache:flush. Well I'll be damned! Flushing the cache every now and 
then seems to be eminent with flow3.

Your example class TYPO3\FLOW3\Security\Account() showed this has been 
tried out and works and I had to look for the problem somewhere else.

Thanks!
Ed

P.S.
Yes object creation is done as you mentioned:
$newUser = new \I\Dont\Know\The\NameSpace\User();
$userRepository->add($newUser);


More information about the FLOW3-general mailing list