0

我的 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(); ?>
4

2 回答 2

3

在您的模型类中,有一个 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

于 2013-04-16T10:05:04.067 回答
-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
));
?>
于 2013-04-16T10:04:26.080 回答