views:

852

answers:

2

When I use the form helper to make a time input,usaually I write code as follows

<?php
$options = array(
    'label' => '',
    'type' => 'datetime',
    'timeFormat'=>'24',
    'separator'=>'-'
);
echo $form->input('Service.endtime',$options);
?>

But now I get a problem that I want to make a time input style such as

month-day-hour

Then how can do this with setting some parameters in the helper?Suggestions would be appreciated.

+1  A: 

Well dateformat option will allow you to configure the date parts.

Used to specify the format of the select inputs for a date-related set of inputs. Valid values include ‘DMY’, ‘MDY’, ‘YMD’, and ‘NONE’. http://book.cakephp.org/view/203/options-dateFormat

However for this I think that you will need to extend the helper and create a custom function which will return this mixed date and time style. Otherwise I can only think of having two selects, one with month and day, and one for hour. Then merging the data somewhere else, perhaps in beforeSave() or beforeValidate()

DavidYell
after going through the form.php in the cake's lib,I got a solution using the single part input function in the helper such as `$form->month()`.Though more parameters to post but still better than do that manually:)
SpawnCxy
Ah cool, handy to know!
DavidYell
+1  A: 

Hope my solution may help someone with the same requirement:

<?php
//echo $form->year('Modelname.year',2001,2021,intval(date('Y')),false)."-";
echo $form->month('Modelname.month',date('m'),'',false)."-";
echo $form->day('Modelname.day',date('d'))."-";
echo $form->hour('Modelname.hour',1,date('H'));
?>
SpawnCxy