开发者

Customize the datetime format in Cakephp

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-ho开发者_StackOverflowur

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


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()


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'));
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜