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

"Christian Müller (Kitsunet)" christian.mueller at typo3.org
Fri Nov 11 13:46:50 CET 2011


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



More information about the FLOW3-general mailing list