Hi, can you help me. The calendar not show today date when i want to update the data in the form.
My code:
1)form.php
<div class="form-group <?php echo (!is_null($model->getError('project_date')))? 'has-error':''; ?>">
<label class="col-md-3 control-label" for="nama"><?php echo $form->labelEx($model,'project_date'); ?> </label>
<div class="col-md-7" id="project_date">
<div class="input-group date">
<?php if ($model->isNewRecord) { ?>
<?php echo CHtml::textField('Project[project_date]', date('d M Y'),
array('size'=>20,'maxlength'=>20,'class'=>'form-control input-md')); ?>
<?php } else { ?>
<?php echo $form->textField($model,'project_date',
array('size'=>20,'maxlength'=>20,'class'=>'form-control input-md')); ?>
<?php } ?>
<span class="input-group-addon"><i class="fa fa-calendar fa-lg"></i></span>
<?php echo $form->error($model,'project_date'); ?>
</div>
</div>
<div class="col-md-2"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
// BOOTSTRAP DATEPICKER WITH AUTO CLOSE
// =================================================================
// Require Bootstrap Datepicker
// http://eternicode.github.io/bootstrap-datepicker/
// =================================================================
$('#project_date .input-group.date').datepicker({
autoclose:true,
todayHighlight: true,
format: "d M yyyy",
});
2)controller
public function actionUpdate($id,$section)
{
if (isset(Yii::app()->session['company_id']) && !empty(Yii::app()->session['company_id']))
$activeCompanyId = Yii::app()->session['company_id'];
else
$activeCompanyId = Yii::app()->user->company_id;
if(isset($_POST['Project']))
{
$model->attributes=$_POST['Project'];
date_default_timezone_set("Asia/Kuala_Lumpur");
$time = date_default_timezone_get() ;
$time = date('Y-m-d H:i:s');
$model->updated_time = $time;
$model->updated_user_id = Yii::app()->user->user_id;
//Section A
if (isset($_POST['BtnUpdate'])) {
$model->project_status_id = 2; // Updated Project
$tempDate = $model->project_date;
$model->project_date = date('Y-m-d', strtotime($tempDate));
}
}
}
Thank you.