symfony's schema can create be used to automate this for you. In your
schem.yml just create a null-value created_at field:
table_name:
field1: { ....... }
field2: { .... }
created_at: ~
symfony will automatically add the date into the created_at field of your
table everytime a record is created. In addition, you can do the same with
updated_at which is automatically changed everytime an UPDATE query is run
on your database.
Now, to answer your question for future reference. I find the best way to
set default values is after you have instantiated your form object in your
action. For example:
$this->form = new SomeForm();
$this->form->setDefaults(array(
"field1"=>"value",
"field2"=>"value"
));
On Fri, Oct 8, 2010 at 12:07 PM, Christian <[email protected]> wrote:
> imo, u dont want to set date_created as hidden field. unset this field in
> your form and set this object attribute if u save this new object.
>
> $myObject->setDateCreated(new DateTime());
> $myObject->save();
>
> Am 08.10.2010 00:04, schrieb Manu SW:
>
> Hi again,
>>
>> I am back with another problem in the same form : I can't get a hidden
>> field to get initialized with a default value.
>>
>> This is a portion of my code :
>>
>> $this->setWidgets(array(
>> 'object_id' => new sfWidgetFormPropelChoice(
>> array('model' => 'BioObject', 'add_empty' => true)),
>> 'user_id' => new sfWidgetFormPropelChoice(
>> array('model' => 'sfGuardUser', 'add_empty' => false)),
>> 'media_file' => new sfWidgetFormInputFile(array(
>> 'label' => 'Mi Video')),
>> 'is_stream' => new sfWidgetFormInputHidden(),
>> 'date_created' => new sfWidgetFormInputHidden(
>> array('default'=> '2009-05-21 16:31:35'))
>> ));
>>
>> The field i want to initialize is 'date_created'. But it never renders as
>> i want, with the default value. It invariably renders :
>>
>> <input type="hidden" name="video[date_created]" id="video_date_created" />
>>
>> I also tried with :
>>
>> $this->widgetSchema['date_created']->setOption('default', '2009-05-21
>> 16:31:35');
>>
>> But no luck either.
>>
>> Would someone have any clue / pointer ?
>>
>> Those are the validators, in case it's relevant :
>>
>> $this->setValidators(array(
>> 'object_id' => new sfValidatorPropelChoice(array('model' =>
>> 'BioObject', 'column' => 'id', 'required' => true)),
>> 'user_id' => new sfValidatorPropelChoice(array('model' =>
>> 'sfGuardUser', 'column' => 'id', 'required' => true)),
>> 'media_file' => new sfValidatorFile(array(
>> 'required' => true,
>> 'path' => sfConfig::get('sf_upload_dir').'/media',
>> )),
>>
>> 'is_stream' => new sfValidatorBoolean(array('required' => false)),
>> 'date_created' => new sfValidatorDate(array('date_output'=>'Y-m-d
>> H:i:s'))
>> ));
>>
>>
>>
>> This project uses symfoiny 1.2.5 with propel.
>>
>> Thanks !
>> M.
>>
>>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<symfony-users%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>
--
Gareth McCumskey
http://garethmccumskey.blogspot.com
twitter: @garethmcc
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en