Development

#2772 (object_input_date_tag input not parsable by $table->setDateField() method)

You must first sign up to be able to contribute.

Ticket #2772 (new defect)

Opened 11 months ago

Last modified 10 months ago

object_input_date_tag input not parsable by $table->setDateField() method

Reported by: dancablam Assigned to: fabien
Priority: major Milestone:
Component: helpers Version: 1.0.10
Keywords: object_input_date_tag Unable to parse date/time value for Cc:
Qualification: Unreviewed

Description

The following code:

<?php echo object_input_date_tag($claimant, 'getBirthDate') ?>

This will generate three select boxes named birth_date[month], birth_date[day], birth_date[year]

On the action when using the following code:

$post = $this->getRequest()->getParameterHolder()->getAll();
$claimant = new Claimant();
$claimant->fromArray($post, BasePeer::TYPE_FIELDNAME);
$claimant->save();

The following error is thrown:

Unable to parse date/time value for [birth_date] from input: array ( 'month' => '12', 'day' => '17', 'year' => '1981', )

The object_input_date_tag generates fields that create an array in the action, but the saveBirthDate method has no logic to handle such an array.

To me it seems the model should be designed to handle results generated by object_input_date_tag without having to manually create logic to parse it from an array to a string before it can be managed. As far as I know all the other object helpers can be handled by the model out of the box - however the date object helper is broken in this manner (unless you use rich mode).

Proposed fix involves adding something LIKE the following to the top of the $script string in the addTemporalMutator function in PHP5BasicObjectBuilder.php:

if(is_array($v)) {
  $v = implode('-', $v);
}

This, obviously, isn't a completely robust fix - but it's something that should be added so that the object date helper can co-exist with the model without excessive intervention.

Cheers, Dan

Change History

01/28/08 19:13:35 changed by dancablam

This is also a problem from the admin generator. Take this instance:

datetime_end:          { params: rich=false 12hour_time=true }

The AM/PM will show in the generator but when, for instance you change the AM to PM - it is not updated in the database to PM because the helper is not parsing the date correctly as it should.

A fix for this would be greatly appreciated.