我遇到CjuiDatePicker的问题。当你处于模式创建时,它正常工作,但是当你处于模式更新时,可以显示时间,我只需要日期。
我该如何让时间消失?我尝试阅读有关此问题,但当我尝试添加dateFormat时,没有任何反应.. 这是我的代码:
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'event-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldRow($model,'event_name',array('class'=>'span5','maxlength'=>255)); ?>
<label for="Event_event_date" class="required">Event Date <span class="required">*</span></label>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'event_date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'slideDown',
'minDate'=>'new Date()',
'changeMonth'=>true,
'changeYear'=>true,
'dateFormat' => 'yy-mm-dd'
),
));
?>
<?php echo $form->textAreaRow($model,'event_description',array('rows'=>6, 'cols'=>50, 'class'=>'span8')); ?>
<label for="Event_event_image" class="required">Event Image <span class="required">*</span></label>
<?php
if(!$model->isNewRecord){
echo CHtml::image(Yii::app()->request->baseUrl.'/uploads/event/'.$model->event_image,'image',array('width'=>300));
echo '<br />';
}
?>
<?php echo CHtml::activeFileField($model,'event_image'); ?>
<?php echo $form->error($model,'event_image'); ?>
<br /><br />
<?php echo $form->checkBoxRow($model,'published'); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
<?php $this->endWidget(); ?>
答案 0 :(得分:2)
在你的模型类中,有一个afterFind()事件处理程序,如:
protected function afterFind(){
$this->event_date = Yii::app()->dateFormatter->format('yyyy-MM-dd', CDateTimeParser::parse($this->event_date, 'yyyy-MM-dd'));
return parent::afterFind();
}
这也可以帮助您:http://www.yiiframework.com/wiki/183/using-international-dates/#hh4
答案 1 :(得分:-1)
<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$this->widget('CJuiDateTimePicker',array(
'model'=>$model, //Model object
'attribute'=>'start_date', //attribute name
'mode'=>'datetime', //use "time","date" or "datetime" (default) <---- use this option to show date, time or datetime
'language'=>'en_us',
'options'=>array(
'regional'=>'en_us',
'timeFormat'=>'hh:mm:ss',
'minDate'=>'new Date()',
'onSelect'=>'js:function(dateText, inst){
enableEndDate(dateText);
}'
) // jquery plugin options
));
?>