最为初始的代码:
$this->widget(‘zii.widgets.jui.CJuiDatePicker’, array(
‘name’=>’mendtime’,
‘value’=>date(‘Y-m-d’, time()),
‘language’=>Yii::app()->getLanguage(),
‘options’=>array(
‘showAnim’=>’slideDown’,
‘changeYear’=>true,
‘changeMonth’=>true,
‘showWeek’=>true,
‘autoSize’=>true,
‘dateFormat’=>’yy-mm-dd’,
‘maxDate’=>’0’,
‘minDate’=>’-10d’,
),
‘htmlOptions’=>array(
‘readonly’=>’readonly’,
‘class’=>’txt’,
‘style’=>’width:200px’
)
));
后期的实现效果:
实现流程:
1、yii 官方网站上的扩展下载:http://www.yiiframework.com/extension/datetimepicker/
2、复制CJuiDateTimePicker文件夹到protected/extensions目录下;
3、到https://github.com/trentrichardson/jQuery-Timepicker-Addon下载语言包,因为yii扩展中没有语言包;
4、在文件CJuiDateTimePicker.php中查找:$cs->registerScriptFile($assets.self::ASSETS_NAME.’.js’,CClientScript::POS_END);在其下添加一行:
$cs->registerScriptFile($assets.’/i18n/jquery-ui-timepicker-‘ . $this->language . ‘.js’,CClientScript::POS_END);,以加载语言包;
5、视图中的代码:
<?php
Yii::import(‘application.extensions.CJuiDateTimePicker.CJuiDateTimePicker’);
$this->widget(‘CJuiDateTimePicker’, array(
‘name’=>’mendtime’,
‘value’=>date(‘Y-m-d H:m:s’, time()),
‘language’=>Yii::app()->getLanguage(),
‘options’=>array(
‘showAnim’=>’slideDown’,
‘changeYear’=>true,
‘changeMonth’=>true,
‘showWeek’=>true,
‘autoSize’=>true,
‘dateFormat’=>’yy-mm-dd’,
‘timeFormat’=>’hh:mm:ss’,
‘maxDate’=>’0’,
‘minDate’=>’-10d’,
),
‘htmlOptions’=>array(
‘readonly’=>’readonly’,
‘class’=>’txt’,
‘style’=>’width:200px’
)
));
?>
注:
1、$this->language必须与js文件中的一致,其默认为zh-CN,而假设$this->language为zh_cn,则需要全部修改为与$this->language相一致,不然运行不正常;
2、日期、时间格式设置与php中date是不一致的,而是
‘dateFormat’=>’yy-mm-dd’,
‘timeFormat’=>’hh:mm:ss’,
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250337.html