用CakePHP显示当前日期
我已经为datepicker使用了一个脚本,如下所示用CakePHP显示当前日期,php,cakephp,Php,Cakephp,我已经为datepicker使用了一个脚本,如下所示 <script> $(function() { $( ".datepicker" ).datepicker({dateFormat: 'yy-mm-dd'}); $('.timepicker').timepicker({ timeFormat: 'H:mm:ss p' }); }); </script> $(函数(){ $(“.datepicker”).datepicker({dateFormat:'yy
<script>
$(function() {
$( ".datepicker" ).datepicker({dateFormat: 'yy-mm-dd'});
$('.timepicker').timepicker({ timeFormat: 'H:mm:ss p' });
});
</script>
$(函数(){
$(“.datepicker”).datepicker({dateFormat:'yy-mm-dd'});
$('.timepicker').timepicker({timeFormat:'H:mm:ss p'});
});
这将在文本字段中显示日期选择器
<div class="bit-4 pad-small">
<label>Trip Date</label>
<?php echo $this->Form->input('trip_date', array('label'=>false,'type' => 'text','placeholder'=>'','maxlength'=>'30','class' => 'datepicker','required')); ?>
<span>required</span>
</div>
旅行日期
必修的
但是我希望当前日期自动显示在日期列中。您可以使用php
date()
函数将值设置为当前日期。有关格式设置选项,请参见以下链接:我想这个代码会对你有帮助
<?php echo $this->Form->input('trip_date',array('label'=>false,'type' =>'text','placeholder'=>'','maxlength'=>'30','class'=>'datepicker','required','value'=>date('Y-m-d')));
您需要使用默认
属性而不是值
属性来设置输入的默认值:-
<?php
echo $this->Form->input('trip_date',array(
'label' => false,
'type' => 'text',
'placeholder' => '',
'maxlength' => '30',
'class' => 'datepicker',
'required',
'default' => date('Y-m-d')
));
?>
如果使用value
它将覆盖通过$this->request->data
传递的任何表单数据,这通常不是需要的<如果没有通过$this->request->data
传递输入值,则code>default
为输入值提供一个值。如果您使用Tanbir Sagar的建议,那么如果您的表单数据中存在验证错误,您的trip\u date
字段每次都将重置为当前日期。虽然您的答案在我看来是正确的,但如果您解释您所做的事情以及原因,可能会对OP有所帮助,以便OP可以从中学习一些东西,而不仅仅是复制/粘贴此代码。